Understanding LINQ to SQL Query Translations
I posted two blog posts last weekend about using LINQ to easily perform data access against a database. Several people have asked me for more details on LINQ to SQL since then.
Sahil Malik made some excellent posts earlier this summer that go into more detail about LINQ to SQL (aka DLINQ) and how it works. You can read his posts here:
- An Introduction to DLINQ
- Setting Up a DataContext Class
- Querying for Data using DLINQ
- Stored Procedure and UDF support in DLINQ
- Stored Procedures that return a Definite Shape with DLINQ
- Stored Procedures that return a Variable Shape with DLINQ
- DLINQ: Submitting your Changes
Bill Wagner has also recently made several great posts that go into more detail about how LINQ queries are translated and executed as SQL. You can read his posts here:
- LINQ to SQL Introduction
- LINQToSQL: Translating C# to SQL
- LINQ For SQL Queries: Where Clauses and Database Queries
- LINQ for SQL Queries: Mathematics Functions
As I talked about in this recent blog post, one of the really cool things about LINQ is that you can always hover over a LINQ query while in the debugger to drill in and see the underlying SQL query that is ultimately executed:
You can then expand the debug visualizer to both see and execute the underlying SQL query while in the debugger:
This provides a really cool way to see what is happening under the covers and to easily experiment and adapt your queries however you want.
Hope this helps,
Scott