Hi, we r coming!! Live report is coming up soon!



Great Ocean Road:
What a funny story! Today I went to Her Majesty Theatre, watched the most famous musical in the world – Mamma Mia!
I love the theme song, Dancing Queen.
.NET FX introduces a powerful weapon for creating the compact, breezy and elegant code in your project. The weapon’s name is as complicated as the mathematical stuff, called Lambda expression.
As the name implies, the great convenience comes great complication inside. Lambda expression is too important to understand, it is useful and I think it is good to know how it works. Well, it’s not as complicated as we think, just a little bit confusing when using it.
First of all, Lambda is used for 2 purposes. 1 is to simplify delegation, 2 is to create expression tree. In my case, I need to create lambda expression to create dynamic query.
Imagine the following usecase:
In your product table, there is a field called “Tags” and it’s used for storing the CSV (comma separated value) like “car, mazda, suv, luxury”, you have many records:
Product Table: (Table name: ProductTable)
ID   ProductName   Tags
1   Tow bar      car,mazda,suv,luxury
2   Cup holder   car,luxury
3   Phone holder   car,mazda
4   FM Transmitter   car,suv
5   Queens bed   luxury
6   DVD Burner   car,BMW,x5,luxury
When your searching criteria is
“mazda” and “luxury”, the following records would be selected out:
ID   ProductName   Tags
1   Tow bar      car,mazda,suv,luxury
2   Cup holder   car,luxury
3   Phone holder   car,mazda
5   Queens bed   luxury
6   DVD Burner   car,BMW,x5,luxury
In ancient SQL age, you would probably write a SQL like this:
string SQL = “SELECT * FORM ProductTable WHERE Tags LIKE’%mazda%’ OR Tags LIKE ‘%luxury%’”;It is IMpossible to create SQL like above except the project scope tells you the fixed keywords that would be used, the keywords should flexible. Then the code would be as much as:
string[] tags = new string[]{“mazda”, “luxury”}; string SQL = “SELECT * FROM ProductTable WHERE 1=1″;You must be very exciting that your code supports as many keywrods as it can. (I did before, I mean I would be very exciting when the code filled with logical stuff, LOL, of course, not now, that’s what geek did before~ )
Back to the reality, to the modern age, with the lambda expression, what you need to do is:
(pre-condition: you have created corresponding domain model which mapped to the database.)
The domain object or entity would look like:
to fullfill the same kind of logic as the stone-aged people do, you just need to
DataContext db = new DataContext(“<connection-string>”);Since so far, you still feel comfortable with this, but after minute, you would probably wanna go back stone age, how do we dynamically create the query in this case? Unfortunately, there is no short-cut for this, but many people provide lots of solutions on the Internet. We can either download some source codes about dynamically query on Internet or just grab the codes from the blogger’s website.( Most of time, you can’t use all of their codes posted on the blog, the codes are broken and bad structure, remember what Koumei always suggests, absorb the mind from the other coders, do not copy the code they provided. )
But in here, I would rather to use Expression Tree to implement the dynamic query.
First of all, we need to create an expression, because it would be applied to IQueryable.Where(Expression<Func<ProductTable, bool>> expression), so the expression should be defined as:
public static System.Linq.Expressions.Expression<Func<ProductTable, bool>> ApplyTags(IEnumerable<string> tags) //parameter is the collection of tagsAgain, you can’t copy the code, since you would NOT have the same object like ProductTable and the same “Tags” property as I do. Luckily, you still can copy the code that I provide later, which is using the magic of template or generic programming. Before that, let us see how to use it:
IQueryable all = table.Where(ApplyTags(new List{“mazda”,”luxury”})).AsQueryable();Since so far, I am 100% sure you can do it like refactoring, re-structuring to optimize your code. However, I would like to provide the code which can be general used:
public static System.Linq.Expressions.Expression<Func<T, bool>> ApplyFilter<T>(IEnumerable<string> filters, string property)The usage is similiar:
IQueryable all = table.Where(ApplyFilter<ProductTable>(new List{“mazda”,”luxury”}, “Tags”)).AsQueryable();Not that hard, right?
Enjoy the powerful weapon, but don’t hurt yourself, bacause the deadline is ahead!
Never seen this before. In the morning I just plan to go outside, but unfortunately or you may say luckily something wrong with my navigation, I could not turn it on! Then I stay home and try to fix my GPS. About 2pm, it turns a sudden rain, heavily. Soon I heard some noises from the roof, become louder and louder, even deafening. I think the house is gonna break down! My goodness. It is a big hail storm. Hitting the tree, house and the car outside.
The hailstones are no where!
And the power is cut for about 4 hours.
Here is the abridged news from abc.net.au:
Hailstones the size of golf balls have hit the suburb of Melton, in Melbourne’s west, as a line of storms moved through western Victoria.
……………….
Melton, on Melbourne’s northwest fringe,  was one of the first suburbs to feel the storm’s wrath.
(Tell you what, Melton is the place where I plan to go, roughly 35KM from CBD Melbourne.)
Lucky me! I love my GPS, really love it. Actually I blame it why it stops working when I get into the car. But now I understand, it stops to save me from hitting by the hailstorm! And always give me direction when I am lost.
Do you have an experience that life just feels like a movie show? I bet many people do. Someone comes in your life, someone leaves. I think there would be 1000 of people walk beside you everyday who just passing by. You never know their names. By any chance, you meet someone who is passing by, and catch the name. Soon you guys develop relationship. Do you believe that is the fate?
500 Days of Summer is such a good movie, that let people think something seems meant to be, a decision, a response could easily make things different. But who knows? If everything is meant to be, why should we spending time to explore our life? In the story, Tom believe that the girl,whose name is Summer, is the one of his life, he spends his time with her, hanging out together, they seem like couple, lover. Summer gets merry, but her husband is not Tom. At the end of story, the movie mentions that Tom finally figure out that there is nothing meant to be, and he meets a girl who is a competitor of his new job. Will Tom fall into another 500 days again? I hope not.
Good story , good movie and it is a real, or much closer to real life. I strongly recommend it.
All his life is dreaming of adventure, finally, he is taking off!
It is a moving story at the very beginning when he is living with his wife before the exploration. It’s pity that he can’t take his wife who encourage him to take the adventure
What’s the story of the movie? Well, I think pixar is gonna tell us, an adventure could be a lifetime, as long as you still dream of it. But it would become a true story when stop dreaming, just take off today!
First of all, Happy new year~
Yummy foods and happy David’s big day!
(last updated: 31 Dec 09Â 21:01 GMT+8)
(last update: 21:07 GMT+8)
You guys are perfectly natural!
(last update: 21:10 GMT+8)
(last update: 21:19 GMT+8)
What kind of background music is good for this Christmas? It takes me quite a while to figure it out. After reviewing heaps of Christmas albums, finally my verdict is Diana Krall’s “Christmas Songs” album released on December 2005, but still a good album for this holiday.
You can easily download from iTune, RRP $16.99 on iTune.
I like her voice singing “Have Yourself A Merry Little Christmas”, it is romantic.