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

Beginning LINQ development, Part 2

LINQ, the Language Integrated Query, dramatically changes database programming in Visual Studio 2008. Here we examine the ins and outs of LINQ to SQL queries.

Our previous Beginning LINQ development tip offered an introduction to LINQ to SQL queries and to the use of LINQ in ASP.NET applications.

Much has been written in subsequent months about LINQ, the Language Integrated Query, which as you have probably determined by now is a focal point of Visual Studio 2008 programming. Here we revisit LINQ to SQL basics and also point to tutorials on topics such as monitoring LINQ to SQL performance, building LINQ providers and

Getting up close and personal with LINQ to SQL. Scott Guthrie has become synonymous with "long, in-depth tutorial," and he has been working on a LINQ to SQL series for quite some time now.

  • Part 1, as one would expect, is an introduction to the LINQ to SQL designer inside Visual Studio 2008 and provides a few basic code examples in VB and C#.
  • Part 2 dives into the processes of creating data model classes, using entity classes (which map directly to or from a database), and using stored procedures within LINQ to SQL.
  • Part 3 takes a look at database queries and how they can be modified to return specific subsets of information, all while taking advantage of IntelliSense, refactoring and compilation checking.
  • Part 4 demonstrates how LINQ can be used to insert and delete data in SQL databases and how custom entities can be used to validate both objects and methods.
  • Part 5 looks into data binding for Web applications using a control called asp:LinqDataSource, which binds directly to a LINQ-enabled data model and thus can take advantage of LINQ's object-relational mapping capabilities.
  • Part 6 talks about the use of database stored procedures and the ability to map them to data model classes; also discussed is the process of calling user-defined functions.
  • Part 7 shows how stored procedures can be used to modify SQL databases -- and how this process is not much different that it would be if one were to use dynamic SQL.
  • Last but not least, Part 8 covers the use of custom SQL expressions.

LINQ to SQL performance. Here Rico Mariani built a rather "harsh test environment" in which to test the performance of LINQ to SQL, or queries to a SQL Server database.

  • Part 1 introduces that test environment and reviews the metrics that came up when performance was first monitored.
  • Part 2 discovers the problem -- "It was the per-query costs that seemed to be the greatest trouble spot in the then-current profiles."
  • Part 3 describes how to tweak entity management and data binding within the query
  • Finally, Part 4 provides the code syntax for the new build and demonstrates the performance gains to be found in compiled queries.

Building LINQ providers. Matt Warren has put together a nice three-part series on how to use IQueryable and IQueryProvider to build a LINQ provider, which is a way to make a data source accessible through LINQ.

  • Part 1 introduces the properties of these two public interfaces and offers some basic information on how to implement them.
  • Part 2 demonstrates how to build the LINQ provider so that it will translate the query into SQL command text and translate the result of executing that command into an object.
  • Part 3 extends the LINQ provider to numerous operators that all share complex interactions.

Let's get visual. If staring at paragraphs of text and lines of code gets you down, then the Visual Basic team at Microsoft may have just what the doctor ordered. Among the "How Do I" videos that the development group has posted is a five-part series highlighting Visual Basic 2008 and LINQ. Moreover, there are two videos of interest on Channel 9 -- LINQ to SQL and the O/R Designer in VS 2008 and Visual Basic LINQ Syntax in Visual Studio 2008.

Oh, and one more thing. In case we missed anything, Fabrice Marguerie has compiled a helpful LINQ link list. Try saying that five times fast.

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.