Linq

By torgeirhelgevold

Version 3.5 of the .Net framework introduced Linq as new way of dealing with object models.

I haven’t had time to play with Linq extensively, but my impression so far is good.

Linq uses a model where content from your data source is mapped into objects, or entities if you like that notation better.

A typically Linq scenario is to build an object model around a relational database where each table will be represented by a typed object in your object model. The Linq framework will aid you in generating the actual entity classes and all CRUD statements. The framework will also maintain/expose a data context which serves both as your connection to the database, and your channel for invoking actions on your data source. The data context will do all the book-keeping of object state (insert, update, delete) as well. The only requirement is that you keep the context “alive” until all changes have been submitted to the database.

Linq can also work with other data sources such as Xml, but if you ask me; its real strength comes from the ability to query typed objects in collections. Any collection implementing IEnumerable<T> can be queried using Linq. This can save you a lot of “foreaching” when trying to filter a collection based on specific parameters.

The syntax of a Linq query resembles Sql syntax, which makes it an easy transition if you have some experience writing basic Sql.

Tags: ,

Leave a Reply