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:

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:

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

22 Comments

  • To be able to look at the query is a great stuff

  • Yeah this was added in the May CTP. IMO this is very useful. It would be rather nice if this visualizer was extended to display execution plan as well.

    Of course what happens in this space is highly dependent on where ADO.NET eF goes versus LINQ to SQL.

    I'm of course Curiously waiting .. :)

    SM

  • Thanks Scott,

    If I wanna use LINQ in my ASP.NET project,
    should LINQ be installed on the server or it is sufficient to copy the required dll files into the bin folder?

  • im sorry to ask such simple question about i test LINQ with my VS2005 pro edition. i just only installed C# library. my problem is cannot find the LINQ project as you showed us. appwiz.cpl told me i had aleady installed the LINQ MAY 2006 download from LINQ default page.is it VS2005 edition problem? thx.

  • Hi Champs,

    To use LINQ you'll need to install the May CTP release of it. This installs on top of VS 2005.

    Hope this helps,

    Scott

  • Hi Majid,

    The easiest way is to install LINQ on your server as well. It uses new compilers at compile-time -- which you'll need to make sure are installed if you are using a VS 2005 Web Site Project.

    One alternative would be to use a VS 2005 Web Application Project. In this case you will need the compilers installed on your development machine, but not on the server. Instead you can simply copy the LINQ dlls as part of the \bin directory of your application.

    Hope this helps,

    Scott

  • Hi Scott,

    Do you know when a final release of LINQ is coming?

  • Hi Scott,

    Can you use LINQ together with AJAX in same project?

  • Hi Seth,

    Absolutely. LINQ and Atlas go together really, really well. :-)

    Hope this helps,

    Scott

  • Hi Dmitiy,

    The final release of LINQ will come next year. We are also looking to have a "go live" license that you can use to deploy apps with it before then.

    Hope this helps,

    Scott

  • Hi Anubhav,

    Lots of people like to debate SPROCs vs. embedded SQL in the middle-tier. The good news is that LINQ supports both options. So if you prefer SPROCs, you can use them to perform LINQ queries against (check out Sahil's articles above for you this works).

    Hope this helps,

    Scott

  • Scott, what is your take on the SPROC vs. SQL debate?

  • Hi Ethan,

    I think there are pros and cons to using SPROCs vs. SQL directly. Sprocs have some advantages in that they can be locked down and secured tighter, and they provide the ability to better control the SQL that executes against your database (which can sometimes lead to better perf if done right).

    Having said that, object relational mappers like LINQ (and others) really do provide a ton of flexibility and productivity that is hard to ignore. They also make it easier to model your business entities and logic.

    Hope this helps,

    Scott

  • Hi Bohemian,

    I wouldn't think of LINQ as a RAD feature (meaning designer/wizard focused). Rather I think of LINQ as a way to radically improve the expressiveness and query capabilities of ORMs (object relational mappers).

    The benefit of an ORM approach to data is that it allows you to model your business entities and logic much better, and helps break down some of the impedence mismatch that exists today between rows in a database and objects in the middle-tier. As such, technologies like LINQ can make a huge improvement to enterprise applications and solutions.

    Note that one of the benefits of LINQ is that it still allows you to drop down and execute custom queries or call SPROCs directly if you want - without loosing most of the big benefits of LINQ. So in cases where you/want need to-do this you can still do so.

    Hope this helps,

    Scott

  • Hi Bohemian,

    By impedence mismatch, I mean that when you retrieve data from a database you get back a row object containing some raw relational data, but loose many of the semantics that the data has in the database. When you then work on it in an object oriented world it becomes further disconnected from the underlying data model, and when you update it you need to write a lot of custom code to do things right.

    The nice thing about LINQ (and other O/R approaches) is that it preserves the underlying data semantics without you having to write any custom code to make this happen.

    Hope this helps,

    Scott

  • Hi Scott,

    You mentioned earlier that Linq will officially release 'next year' -- do you know approximately when? I'm trying to convinve my partners to put off a project until Linq releases, and I'd like to have some idea when the final release will be available. Any degree of granularity is fine - I just need something to *say,* if you know what I mean. =)

    Thanks a bunch,
    Erik

  • Hi Erik,

    My guess is that the final release will be in the second half of next year -- although that is very speculative. We will also probably look to have a go-live license at somepoint before that if you wanted to go live in production prior to the final release.

    Hope this helps,

    Scott

  • Hi Mads,

    The intellisense support in the CTP is not there (it instead uses the old VS 2005 intellisense engine for C# -- which doesn't recognize the new keywords yet).

    The real intellisense will start to show up early next year.

    Hope this helps,

    Scott

  • When will LINQ release?

  • Hi NGoc,

    LINQ will ship as part of the "Orcas" release of Visual Studio and the .NET Framework. We are currently planning to ship this the second half of 2007.

    Thanks,

    Scott

  • Is there an "Orcas" version of .Net Framework? So, what is the difference between that version of .Net Framework with the current version 3.0?

  • Hi Ngoc,

    There will be an "Orcas" version of the .NET Framework coming. This will be the version after .NET 3.0.

    Thanks,

    Scott

Comments have been disabled for this content.