Home » Linq

One of my team mate would like to query some data with Linq but has always an error message saying that the Linq to Entity couldn’t find the property desired. In fact, the exception was relevant because the property was made up in the model and were using two others properties available from the database. To figure out more about the problematic...
If you have Resharper, you can see sometime a warning saying that you “Access to modified closure”. If you do not have it, you can still have odd behavior something with the values. In both case, this mean that Linq is accessing a value that might (or not) be modified. Linq execute delegate functions. If you try : var listInteger = new...
Filed in: Linq
Lets imagine that you have a collection with a class containing Images. All images are identified by an unique key and a caption that the user enter. You want to verify that the caption entered by the user is unique to the collection. How to do it? This can be done with Linq to Object pretty easily by using 2 from statement. var hasDouble = ...
Filed in: C#, Linq

Lambda Expression

Posted by on September 28, 2011
Lambda Expression can be of two types: Code Delegate (compiled) Expression Tree Object (runtime) The Code Delegate is used a lot with Linq. Almost all extension like Where is a delegate function that is compiled into IL code. It’s very fast because it’s compiled. On the other hand, some situation when the data is not evaluate against...
Filed in: Linq
It’s possible to perform a Cross Join with Linq. A Cross Join is a Cartesian product. It means that if between 2 sets of value all value will join one time the other set. For example: If we have one set with the letter A and B, and a set with C, D, E than the result should be : A-C, A-D, A-E, B-C, B-D, B-E. Let do it in code. var x = new string[]...
Filed in: Linq
Linq let you query a collection and one of its possible action is the GroupJoin. A GroupJoin is in SQL what we call a “Left Outer JOIN” while a Join in SQL refer to “Inner Join”. In short, a GroupJoin will do a link between 2 entities even if the right side of the link has nothing to link to. In contrast, the Join will link 2...
Since few months I have notice that some people near of me still do their join between table in the Where clause. It works even if it has its limitations but the biggest problem come for the maintenance. Later, a big query become hard to modify because the criterion to refine the upcoming data are mixed up with joining where clauses. To solve...
Filed in: Linq, Sql
wordpress themplates