Register   |   Login

 

Spark Your Solution

 Scott's Technology Blog Minimize

Oct 7

Written by: Scott Davis
10/7/2009 7:27 AM

Here is the demo code I used during the MSDN webcast with Mike Benkovich. This demo project shows how to see what LINQ to SQL is doing under the covers, when you execute a LINQ to SQL query. The webcast was first promoted using this URL. 

 
http://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?EventID=1032427067&EventCategory=4&culture=en-US&CountryCode=US
 
You can likely watch the the replay with the same URL, however if that doesn't work, I'm sure you can search for the reply by title, or find a link from http://www.BenkoTips.com
 
  
Notes about the project:
 
You will need the Northwind database to run this code. To obtain the Northwind database follow this link.  Be sure to see the install instructions on the download page to find the install directory.
 
http://www.microsoft.com/downloads/details.aspx?familyid=06616212-0356-46A0-8DA2-EEBC53A68034&displaylang=en
 
Undoubtedly, you will need to change the connection string in the app.conf file to point to your database. You may find it easier to completely delete the Northwind.dbml file in the application and create a new one from scratch, following the creation screens to point to your database. I simply included all tables from the database for ease of setup, and you can do the same.
 
The project is setup initially to run the Employee Sales queries. However, you will need to create the stored proc in your database before you can run that sample. The TSQL to generate the stored proc is included in the code comments for that button click event. Be sure to reference the stored proc in your DBML file once you’ve created it. The same is true for the View that is references in the Customer Queries.
The value of this application comes from the debugging you can do. In the first part of the demo I used the SQL Visualizer to see what SQL will be executed for the query. You can obtain the SQL Visualizer by finding the link on Scott Guthrie’s tutorial and following the installation instructions.
 
 http://weblogs.asp.net/scottgu/archive/2007/07/31/linq-to-sql-debug-visualizer.aspx
 
You will want to investigate the value of the query variables (defined as a “var” type) to see the generated SQL, using the SQL Visualizer.
To run the Customer Sales queries, be sure to remove the column templates in the XAML of the ListView before running these queries, or you won’t see any results. For these queries we are using the DataContext logging feature to see what queries LINQ  is running. Check your Visual Studio “Output” window for the generated SQL. The application will seem extremely slow when logging is used. Disable the logging to see the real performance of the queries. 
 
I’d like to give a special thanks to Jim Wooley, MVP and co-author of the book “LINQ in Action”. Jim (@LinqKinq) saw my tweet on twitter concerning the webcast and reached out to me, offering help. Thanks to Jim for his suggestions and help in preparing for this presentation.
As always, I thank my friend Mike Benkovich for his offer to help him do this webcast, and his fantastic support of my community efforts over the years.

Tags:

Your name:
Title:
Comment:
Add Comment    Cancel  

  
 Blog Dates Minimize

 Print   
 Search Minimize

 Print