Last year at PDC I was nearly jumping out of my seat when I saw LiNQ for the first time at the keynote. LiNQ is the powerful and flexible API that enables in-memory querying across objects, xml and data which is being built into .NET vNext (Orcas) and has been so far incorporated into VB9 and C#3.0. As a former FoxPro developer I couldn't help but recognize the significant FoxPro influence on this new technology. A few hours later I saw Alan Griver, an old friend from my FoxPro days and at that time, the head of the Visual Studio Data team at Microsoft. (As of this past Monday, Alan has moved to a new position at Microsot which you can learn about on his blog.) I said to Alan ("said" is an understatement since I was so excited) "Alan! Alan ! That LiNQ! OMG, it's FoxPro!" Alan smiled at me and said, "Obviously Julie, you haven't been reading my blog because I have been hinting at it for the past 6 months". Oops. :-)
That was September last year. Not only were we seeing LiNQ for the first time, but a lot of other new things such as Atlas, the new designers, Vista and lots of the WinFX stuff. Major overload.
I played with LiNQ enough to demo some of the hands on labs at the Vermont.NET meeting a week later and then set it aside since it was so far off.
Fast forward to this past week at DevTeach in Montreal, where Alan gave the keynote on Tuesday morning entitled "Standardizing access to data with the LiNQ project". I woke up 15 minutes before the keynote was scheduled and raced downstairs because I didn't want to miss it. Good plan. The talk was awesome.
Alan started out introducing us to some of the language innovators at Microsoft who, unbeknownst to each other were exploring in-memory querying in .NET. First was Eric Meijer who was playing with XML querying, originally called X#, that evolved to XEN and then was brought into Microsoft Research as C-Omega. Alan had some fun giving us some insight to what makes Eric tick.
Next was Calvin Hsia who was on the FoxPro team, Paul Vick who is a VB language designer, (someone from the SQL team who I'm sorry I didn't write down) and then Andres Hejlsberg who is the chief architect of the C# language.
All of these people were doing somewhat related work in their own areas and Alan brought them together to compare notes and see if they could find a way to bridge their work. The various groups were then tasked with evolving different areas of LiNQ. If I remember correctly, Calvin Hsia's group focused on the sequence operators (operators are a key part of how querying works) while the VB folks worked on a single syntax and the C# group looked at querying from a lower level of what data, objects and XML had in common that would enable a common way to query them.
In the long run, they have come up with three APIs:
- LiNQ: to query against any .NET object that is implements iEnumerable
- DLINQ: to query against databases
- XLINQ: to query XML
Before the querying could be implemented, it required some major innovations in the languages themselves, and it seems that the VB team is currently winning hands down with this with respect to the XLiNQ querying.
With LiNQ, you are able to query over a collection of enumerable objects and return only those objects (and specified properties of the objects) that meet your criteria. This could be a string array that you created, a list of methods from a type that you are accessing through reflection, any .NET object at all that meets the criteria of being iEnumerable. Imagine being able to look at a collection of something as simple as integers (or something even much more complex) and without having to iterate through it with a ForEach, ask it to return all of the integers larger than a particular value. Or a collection of datarows. Or a collection of [fill in the blank!].
DLiNQ uses the same LiNQ syntax to query SQL Server databases. DLiNQ converts the query into a LiNQ operator tree and then from there translates this into TSQL then sends the TSQL over to SQL Server. You need to specify a DLiNQ data class in advance that wil have knowledge of the connection string and database, but then it is not necessary to instantiate all of the ADO.NET objects required of a query. One of the most interesting thing about DLiNQ is that the query won't actually be run until the moment that you request the results of the query.
Last is XLiNQ which saves the common man from having to learn XQuery and XPath. The syntax is much simpler and though VB and C# can leverage the same functionality, VB goes a step further and enables developers to work directly with the xml data type. You can literally drop xml in to define and xml data type like so:
Dim myXML =
<PERSON>
<FIRSTNAME>Julie</FIRSTNAME>
<LASTNAME>Lerman</LASTNAME>
</PERSON>
You can use XQuery to create, read and query xml. The coolest thing is the ability to do something reminiscent of using epxressions in ASP/ASP.NET.Alan referred to these as expression holes.
Imagine you are iterating through an object oPerson that has a property frstname and lastname. You can build XML with XLiNQ like this
dim myPersonXML=
<PERSON>
<FIRSTNAME><% oPerson.firstname %></FIRSTNAME>
<LASTNAME><% oPerson.lastname %></LASTNAME>
</PERSON>
Alan's talk was filled with myriad demos which I can't do justice to in a blog post, but look for the many already existing articles and videos (eg Channel9) on LiNQ. The latest CTP had been released just that day so Alan was able to share with us the newest of the LiNQ innovations including the query syntax solution to problems in Intellisense caused by starting out with SELECT. Now queries start with “FROM“ and Alan mentioned that Matt Warren has dubbed the new syntax “Yoda Speak“. Matt writes about another very cool piece of the latest DLiNQ, which is the inclusion of the generic interface iQueryale and the associated method ToQueryable().
Luckily for me, Alan did this talk again on Thursday night at the Vermont.NET user group. So I was able to see and pick up more details about LiNQ.
On a personal note, Alan and Beth Massi both flew into Burlington the day before we headed up to Montreal for DevTeach. Beth, who is an MVP Achitect did three sessions at DevTeach. They then returned to Vermont for the VTdotNET meeting and then to visit with my husband and I for a few more days. I dropped them off at the airport this morning. We had a wonderful time even it has been raining nearly non-stop for days and days, we were able to share with them some of our favorite Vermont treasures, such as the Shelburne Museum.
Resources to get you started:
LiNQ Home Page on MSDN
Future Versions on MSDN