Language Integrated Query Article Index for
Language
Website Links For
Language
 

Information About

Language Integrated Query




LINQ defines ''standard query operators'' that allow code written in LINQ-enabled languages to filter, enumerate, and create projections of several types of collections using the same syntax. Such collections may include Array s, enumerable Class es, XML , datasets from Relational Database s, and third party data sources. The LINQ project uses features of version 2.0 of the .NET Framework , new LINQ-related assemblies, and extensions to the C# and Visual Basic .NET languages. Microsoft has distributed a preview release of LINQ, consisting of those Libraries and Compiler s for C# 3.0 and Visual Basic 9. Other languages, such as F# and Nemerle , have also announced preliminary support.


LANGUAGE FEATURES

LINQ uses several new language features to expose query syntax natively to languages such as C#:


DATA SOURCES

Although LINQ initially supports queries of in-memory collections, relational databases and XML data, it is an extensible architecture that allows third-party providers of additional data sources to expose their data sources for use with LINQ by implementing the Standard Query Operators as Extension Method s for those data sources, or by implementing the IQueryable interface that allows to parse an expression tree at runtime to translate it into some query language. The Standard Query Operators are used by LINQ to Objects as well and allow to query in-memory objects with the same LINQ syntax. A custom implementation of the Standard Query Operators exists as a community sample {Link without Title} .

For example, LINQ to SQL (formerly DLinq), which translates LINQ expressions into SQL database queries, makes use of the compiler's ability to build an expression tree from source based on context, rather than building a function delegate. Given the expression tree describing the query, a database-specific provider can analyze and transform it into the appropriate query language for the data store, such as Microsoft SQL Server, Jet (used by Microsoft Access), or third-party database servers. Some individuals have already created proof-of-concept LINQ libraries for querying WMI LDAP [http://community.bartdesmet.net/blogs/bart/archive/2007/04/05/the-iqueryable-tales-linq-to-ldap-part-0.aspx , Amazon Web Services and SharePoint [http://www.codeplex.com/LINQtoSharePoint using similar tactics.

The existing preview from Microsoft also includes an implementation of LINQ to XML (formerly XLinq), which greatly simplifies XML document construction and querying, using similar patterns. Furthermore, Microsoft is working on ADO.NET vNext, aka LINQ to Entities, which will ship out of band with Orcas.


SQLMETAL

LINQ framework includes a tool named SQLMetal which allows automatic generation of classes directly from a MS-SQL database, allowing very fast and easy integration of code and database.


LINQ CODE SAMPLE


// the Northwind type is a subclass of DataContext created by SQLMetal
// Northwind.Orders is of type Table
// Northwind.Customers is of type Table

Northwind db = new Northwind(connectionString);

// use 'var' keyword because there is no name for the resultant type of the projection

var q = from o in db.Orders, c in db.Customers

"200" && (O.CUSTOMERID

select new { o.DueDate, c.CompanyName, c.ItemID, c.ItemName };

// q is now an IEnumerable, where T is the anonymous type generated by the compiler

foreach (var t in q)
{
// t is strongly typed, even if we can't name the type at design time

Console.WriteLine("DueDate Type = {0}", t.DueDate.GetType());
Console.WriteLine("CompanyName (lowercased) = {0}", t.CompanyName.ToLower());
  • 2 = {0}", t.ItemID --- 2);

  • }




RELEASE DATE


LINQ is planned for release with the ' 2008 has been announced by Microsoft as February 27, 2008.

The latest version of Visual Studio ' Orcas ' is Visual Studio 2008 Beta 2.


EXTERNAL LINKS