Problem solve Get help with specific problems with your technologies, process and projects.

Beginning LINQ development, Part 1

The Language Integrated Query integrates data queries right into VB 2008 and C# 3.0 and works with objects, XML and SQL. This tip highlights resources for getting to know LINQ.

The Language Integrated Query, or LINQ, is one of the most important of the new features afoot in VB 9.0 and C# 3.0.Developers can use LINQ to query to data sources like ADO.NET, SQL and XML. The idea, of course, is that data queries are now an integrated part of Visual Basic and C# and an immeasurable improvement over data integration in the days of preprocessors.

LINQ first emerged at PDC 2005, and though it is intended for the next version of Visual Studio, code-named "Orcas," LINQ is available for use with Visual Studio 2005.

A good starting point for learning more about LINQ is Hooked on LINQ, a wiki for anyone interested in dipping his toe in the water. Among the site's resources are "five-minute overviews" of using LINQ with objects, SQL and XML.

For more on LINQ-to-SQL queries, which were previously called DLINQ queries, check out the Scott Guthrie post Understanding LINQ to SQL Query Translations. (Guthrie is the head of ASP.NET development at Microsoft.) Here you can find hints for working with stored procedures, Where clauses and mathematics functions.

More on LINQ
Commentary: Let's think about LINQ

News: Visual Basic's future: LINQ, Orcas and, yes, VB 6

News: Lhotka on LINQ at VSLive!

For information on an improvement to LINQ-to-XML queries, also known as XLINQ, Fabrice Marguerie has put together a post called LINQ to XSD -- Typed XML programming with LINQ. XSD in this case refers to an XML schema, which is needed to generate the object models that, in turn, manipulate XML data through LINQ. Using the XML Schema gives developers three benefits, Marguerie said -- better readability, type-checking at compile time and IntelliSense support.

Web developers will be happy to learn that LINQ works quite well with ASP.NET applications. Both the Web Site Project, available out of the box in Visual Studio 2005, and the Web Application Project, included in VS 2005 Service Pack 1, support LINQ development. Guthrie has devoted a few blog posts to the topic; sample code is in C#, but he points out that LINQ works equally well in VB.

  • In Using LINQ with ASP.NET (Part 1), he builds an app that binds a collection of objects to a DataGrid and makes uses of Anonymous types and .NET Standard Query Operators. "What is really powerful is that the .NET Standard Query Operators are not a hard-coded list, and can be added to and replaced by any developer. This enables very powerful domain specific implementations," Guthrie writes (emphasis original).
  • In Using DLINQ with ASP.NET (Part 2 of my LINQ series), Guthrie dives into database programming with DLINQ and ASP.NET. Here again the Anonymous type is a star, as it allows developers to pull only the desired column values from a database, as opposed to returning fully populated entity objects. In addition, Guthrie points out, LINQ queries can return sub-collections of objects.
  • In Building and using a LINQ for SQL Class Library with ASP.NET 2.0, Guthrie creates a Web site that references a LINQ-enabled class library. He also looks into object-relational mapping and how LINQ's debugging visualizer can display what database code is "running under the covers."

Finally, if you want to dive into C# and LINQ, then Charlie Calvert has a series of posts for you. Calvert, a community program manager for Visual C#, has written a six-part series called The LINQ Farm, which takes a look at query expressions, query operators, grouping and other LINQ concepts.

Dig Deeper on Visual Studio 2008 and Language Integrated Query (LINQ)

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.