Wednesday, September 26, 2007

10 Things You Should Know About LINQ

10 fundamental things that you should know about LINQ

1. LINQ is Language INtegrated Query where the queries to data sources are written as part of the High Level .NET programming Language (like C# or VB.NET).

2. The queries, which are the language constructs, can be compiled using the language compilers. This ensures type-safety. The queries can also be debugged using the Visual Studio debugger (an awesome feature, I believe)

3. Intellisense can be used to access tables and their columns of a database. This feature is not present in the CTP versions but would be delivered with the Orcas release.

4. LINQ provides Standard Query Operators (SQOs) (like select, union, where etc) to retrieve data from any object whose class implements the IEnumerable interface. This is called "LINQ to Objects". The object, or rather data source, can be virtually anything: a registry collection or a File collection or a database.

5. LINQ also provides SQOs to work with relational data, also called as "LINQ to ADO.NET or DLINK". It is comprised of three parts: “LINQ to SQL”; to query relational databases like SQL Server, “LINQ to DataSet”; supports queries using ADO.NET datasets and datatables and “LINQ to Entities”; to query ADO.NET 3.0 entities (Entities are part of Entity Framework of ADO.NET 3.0)

6. LINQ provides SQOs for XML documents, called "LINQ to XML or XLINK". It also provides a host of new XML-specific features for XML document creation and queries. It can be considered as a powerful replacement for DOM and XPath.

7. WebLINQ, also known as BLINQ, creates CRUD ASP.NET pages (infact, a complete website) against a database using LINQ. It also preserves relationships between tables by providing an option on the aspx pages to view the related records from the related tables. I would suggest you to check this wonderful feature.

8. LINQ not just supports simple queries but also stored procedures.

9. LINQ can be used to query on a join of different datasources. For example an RSS feed of a Blog, a collection object (like registry) and a bunch of rows from a database can all be joined together (using a SQO) and then be queried on.

10. LINQ maintains object identity. In other words, if two queries return the same information (say form a table), only one instance of that table “as an object” is maintained. This makes sure that objects are not created unnecessarily. This is a classic issue in ORM models, which is eliminated here.

With every release of a framework, life for developers is being made easier. With LINQ, so much code has been made simple to write and manage, that it cannot be put in less than a bible. I wonder if someday I would be jobless!

Three cheers to LINQ!

(Reproduced from my Infosys Blog)

No comments: