Jim Wooley searches for the missing LINQ
Jim Wooley, leader of the Atlanta Visual Basic Study Group, presented to the Atlanta C# User Group last night. Or should I say that he presented to the newly re-branded Atlanta Cutting Edge User Group last night? Either way, Jim Wooley presented his patented “Missing Linq” presentation to the group. This is Jim’s third or fourth time presenting this particular topic, which has been on tour to regional code camps, and his familiarity with the material showed through in his insightful and well thought-out slide deck and accompanying demos. This was my first time seeing this material as I missed the Atlanta Code Camp and have been too lame to make it to any of the other region’s code camps like the upcoming camp in Greenville SC (next week!!!).
What can I say about the content of the presentation? LINQ (Language Integrated Query) is a new “unified” programming model which is designed to let developers work with different types of data (relational = SQL = ADO, hierarchical = XML = XML/XPath, and object based = custom) using the same type of syntax. There seem to be two major goals behind this initiative. First – the syntax for todays coding is pretty domain specific and not very declaritive in nature. It’s not always easy to tell what kind of data you’re working with. I’ve stolen a screenshot from Jim’s slide deck here:

Using the new syntax provided by the LINQ implementations, you can take the above code (in screenshot) and re-do it so that you have this style code (stolen from demo code):
XElement x = new XElement("LinqEssentials",
new XElement("Category", "LINQ"),
new XElement("Category", "DLINQ"),
new XElement("Category", "XLINQ"));
XElement y = new XElement("LanguageFeatures");
y.Add(new XElement("release", new XAttribute("version", "2.0"),
new XElement("feature", "Generics"),
new XElement("feature", "Iterators"),
new XElement("feature", "Anonymous Delegates"),
new XElement("feature", "Nullable Types")
));
y.Add(new XElement("release", new XAttribute("version", "3.0"),
new XElement("feature", "Implicit Types"),
new XElement("feature", "Extension methods"),
new XElement("feature", "Lambda Expressions"),
new XElement("feature", "Object initializers"),
new XElement("feature", "Anonymous Types"),
new XElement("feature", "Expression Trees")
));
y.Add(new XElement("release", new XAttribute("version", "9.0"),
new XElement("feature", "dynamic interfaces"),
new XElement("feature", "dynamic identifiers"),
new XElement("feature", "XML Literals")
));
XElement z = new XElement("LinqRocksBecause");
z.Add(x);
z.Add(y);
This is much nicer b/c you can see the elements in a declaritive fashion – you can tell what the XML document contains without having to read through the CRUD of constructing an XML document. VB is even easier to read:
Dim val = <XLinqRocksBecause version=<%= CodeCamp %>>
<LinqEssentials>
<Category>LINQ</Category>
<Category>DLINQ</Category>
<Category>XLINQ</Category>
</LinqEssentials>
<LanguageFeatures forDate=<%= Today() %>>
<release version="2.0">
<feature>Generics</feature>
<feature>Iterators</feature>
<feature>Anonymous Delegates</feature>
<feature>Nullable Types</feature>
</release>
<release version="3.0">
<feature>Implicit Types</feature>
<feature>Extension methods</feature>
<feature>Lambda Expressions</feature>
<feature>Object initializers</feature>
<feature>Anonymous Types</feature>
<feature>Expression Trees</feature>
</release>
<release version="9.0">
<feature>dynamic interfaces</feature>
<feature>dynamic identifiers</feature>
<feature>XML Literals</feature>
</release>
</LanguageFeatures>
</XLinqRocksBecause>
The second major goal of the LINQ initiative is to give developers a unified way to query into these different types of structured data. This is accomplished with a set of extension methods that give the developer a very SQL type of language syntax for queries. Here is an example query.
var results = from f in new DirectoryInfo(@"C:\windows").GetFiles()
where f.extension == ".exe"
select new{f.Name, f.LastAccessTime};
Notice the semicolon – that’s C# code right there. Extremely readable! LINQ offers the ability to join in multiple data sources, change the sort criteria (orderby) and change the output values (including aggregations and calculations). This query syntax will work with SQL data, flat file data, file system object data (as above), XML data, and more.
Jim’s presentation was excellent and he’s going to present it a few more times at various user groups and code camps. Keep up with his blog to learn more. Five stars!