Changed order of LINQ operators for VB 9 by ThinqLinq

Changed order of LINQ operators for VB 9

With the March Orcas CTP, the order of operations has changed for VB LINQ Queries again. No, they have NOT moved Select back to the beginning. In this case, they have moved the Order By clause before the Select. In case you prefer a bit of code consider the following:

May 2006 CTP:
dim res = From fi in New System.IO.DirectoryInfo("C:\").GetFiles() _
Select fi _
Order By LastAccessTime

March 2007 CTP:
dim res = From fi in NEw System.IO.DirectoryInfo("C:\").GetFiles() _
Order By fi.LastAccessTime _
Select fi

Although it seems that this is simply just a reordering, when we consider scope, this change was crutial. In the older version, in order to order the results, we were forced to include the target column in the resultset (Select). By moving the Order by clause up, we can apply the ordering and not require the field to be included as part of the result set. This is key if you are dealing with a public api which doesn't expose the field you want the results to be sorted on. In addition, I found that in some cases the TSQL mapping differed between the VB and C# implementation due to the older placement of the select and order by clauses.

Unfortunately this change means that my test code will need to be manually updated. Ah the joys of working on the bleeding edge. Yet another reason why you shouldn't be developing production applications on the code base (yet).

Posted on - Comment
Categories: LINQ - VB -
comments powered by Disqus