Tuesday, 7 November 2006

Tech Ed - Visual Studio: The .NET Language Integrated Query (LINQ) Framework Overview

We attended a great lecture by the legend Andres Hejlsberg who gave us an insight into LINQ and explained that that LINQ will be included in C# 3.0 and VB.NET 9.0, more information and slides can be found at http://msdn.microsoft.com/data/ref/linq/

Here are some of our notes that we made whilst in the lecture:

He explained that we can use LINQ to query the following out of the box at RTM:
  • any memory objects that implement the IEneriable
  • Datasets
  • SQL
  • Entity Objects

He then whipped up a demo that took memory objects that had a composition relationship, he then queried these using LINQ with both a Lambda expression and by using the new extension methods.
He explained that the new Var object type is used as a strongly typed object and gives you type of the return statement when compiled.
He explained that we can use lambda expression or more gentle syntax which is converted by the compiler into lambda expressions at compile time.
We now also use the anonymous type on the select to create an object when compiled:
select new {c.companyname, c.phone}

He showed a nested in statement creation of new annoymous types on a select for a more hierarchical structure.

He reminded us that as this is just C# you can do anything in your LINQ statement.

He discussed Deferred Query Execution model were the LINQ query is built as a pipeline of separate query steps that is not actually executed until the results are iterated or a method is called on the results.

The LINQ to SQL api ships with a tool that you can point to a db and it will code gen all the objects for querying also there will be a WYSIWYG designer so you can drag tables over to create objects. This api also claims to creates slim SQL will create select, insert, update statements automatically which you can view by looking at database.log object.

The LINQ to XML api also ships which allows us to use XML more declaratively. It allows us to create and query XML which is easier, faster and more functional than XQuery. We can create new XElement objects by giving it a name and any IEnerable object as params and this will create an xml element with all the IEnerable objects within it. We can also query the relational world to create XML using LINQ.

PLINQ is another project that is being developed to use this more declarative way of querying instead of many for loops etc which allows for higher abstraction which means queries can be run in parallel on multi processor environment.
We can check out more info on LINQ over here http://msdn.microsoft.com/data/ref/linq/

No comments: