With their Language-INtegrated Query (LINQ), Microsoft developed a very powerful extension to their .NET programming languages. It offers a uniform technique to query all different kinds of data (SQL, XML, collection of objects, etc.)
There are many introductions and resources at the web about the huge benefits and opportunities offered by LINQ and it is beyond the scope of this blog article to cover them all here. Instead I'd rather like to show you how LINQ meets the upcoming 2009 version of our migration components library (PPJ Framework).
We have extended the built in LINQ support that comes with .NET 3.0 and added options to also query migrated SAL objects, arrays and even table windows.
I have set up a small sample to illustrate some of the new options. Consider a typical table window like the following that is populated from whatever data sources you have.
Now with LINQ I can very easily launch a query against this table window without the need of any "procedural code". I simply declare what kind of information I need:
var orders = from row in App.tblORDERS
where row["colVALUE"].Number >= 500 && row["colORDERSTATE"].Text == "open"
With this simple query I get a collection of all open orders whose value is 500 or more. To verify the results here is a simple output to the console window:
forearch ( var order in orders )
Console.WriteLine ( "Order No" + order );
In a second sample I'll be declaring a similar query against the same table window but will directly create an XML formatted output string of the result:
XElement xml = new XElement ( "orders",
from row in App.tblORDERS
where row["colVALUE"].Number >= 500 && row["COLORDERSTATE"].Text == "open""
select new XElement ( "order",
new XElement ("orderno", row["colORDERNO"].Text),
new XElement ("customer", row["colCUSTOMER"].Text),
new XElement ("value", row["colVALUE"].Number)) );
Here is the result:
This is all done with a single declaration. Just imagine how many lines of code you would have to write to do it the "traditional" way. There are many more powerful query operators included in LINQ and many of those are already known from SQL (GroupBy, Sum, Distinct, etc.).
Entering into the world of LINQ is pretty easy and straight forward. The possibilites using LINQ are virtually unlimited and with the latest PPJ framework all your migrated objects, arrays and table windows are directly available to LINQ without any modification.
If you want to try out a bit of LINQ, you can take a look at LINQPad: http://www.linqpad.net
For many useful LINQ samples you can use this page: http://msdn.microsoft.com/en-us/vcsharp/aa336746.aspx