Wednesday, September 14, 2005

.Net Language Integrated Query

At the PDC05 keynote on tuesday Microsoft gave the first official announcement about the .Net Language Integrated Query (LINQ) support - it definitely seems that the dream of the unified storage is over (they even said so in the keynote) but to ease the pain Microsoft introduces LINQ.

.Net Language Integrated Query will add query capabilities directly into the CLR and this will be supported by both VB.Net and C#. This means that you will be able to use standard query operators directly from within your code. Something like the next line of code:

IEnumberable expr = from s in names where s.Length==5 order by s
select s.ToUpper();

Other standard query operators such as sorting and grouping and aggregation will be available as well. It even allows for nested queries so that you can combine multiple datasources in one - at the keynote they showed a demo in which they enumerated all the processes running on a computer which consumed more then 4 MB.

var query = from p in Process.GetProcesses() where p.Workingset > 4*1024*1024

Afterwards they showed that DLINQ will allow you to map classes declaratively to tables and databases through the use of attribute ( [table] and [database]). So they created a class and mapped it to a SQL database to retrieve some other info about the processes retrieved in the previous query.

In the last step they demoed how you can use XLINQ to create an XML object based on the previous queries - and they created an RSS feed from the data about the in memory process joined with database information. All this was written in about 30 lines of code without having to create any intermediate datatables or custom collections to store the data and without ever having to write some datasource specific code such as creating a datareader, xmlwriter, etc...

It will be possible to use common SQL operators such as select, group by, where clauses, aggregation options, and these operations will be available for any <IEnumerable>-based information source (Or as Don Box said in the keynote - if you can for each it, you can use it - this means e.g. arrays and collections of objects). This language enhancement will be available for XML (XLinq) and is integrated with ADO.Net (DLinq) as well.


No comments: