by mheydt
15.
July 2008 17:45
>
I'm brushing up on my LInQ today for a few reasons. One is that its been a while since I used it because my current client isn't that far ahead and I need a refresher. Second is that I want to build up some interview questions. Third is I need to update an intro to LInQ presentation I have previously built.
The true reason though is that I want to write out a few of my opinions on the technology, and explain a few things from the perspective of how I see them. One of those things is how the new C# 3.0 language extensions facilitate LInQ. I think sometimes that people think that these features were added to C# as independent items that developers have requested. I don't really see it that way, as I think that although they are useful (and very useful at that) by themselves, that they are only added to the language to allow LInQ. If they were not added, the expressivness of LInQ statements would be greatly reduced, and as a matter of fact it would not event be possible.
The following are the new C# 3.0 features and how I see them related to LInQ:
Required for handling query / selection results. Often (mostly) the type of this object may not be of a type that is defined in the system at compile time. An example is a projection of just a few properties from a result object (via select) instead of the whole object. In this case, the compiler / run-time will create an anonymous type whose type (likely a class with with properties) that can be inferred through the a var keyword. This is tightly intertwined with anonymous types.
Required to allow the creation of results from where and select queries.
Required to efficiently code expressions for the selection and projection steps of a query. With out them, you would need to declare a delegate (either explicitly or anonymously) which would add to the coding overhead.
Needed to extend existing classes to have new LInQ methods such as .Where, .OrderBy, .Select, ...
Allow the compiler / run-time to efficiently initialize properties of anonymous classes. Without them a constructor would need to be injected into the anonymous class.
Provide a syntax similar to SQL, which is used to manipulate data, but provides a short-hand for the coder that the compiler converts into specific classes and method in LInQ.
073fe17f-cf7c-41d7-8b6f-bf2a8cb0490e|0|.0
Tags:
.Net | C# | LInQ