O'Reilly logo

WCF 4.0 Multi-tier Services Development with LINQ to Entities by Mike Liu

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

View Generated SQL statements

You may wonder which actual SQL statements are used by LINQ to Entities to interact with the databases. In this section we will explain two ways to view the generated SQL statements used by LINQ to Entities queries.

There are two ways to view the generated LINQ to Entities SQL statements. The first one is to use the ObjectQuery.ToTraceString method and the second one is to use SQL Profiler.

View SQL statements using ToTraceString

First let's write a new test method to contain one LINQ to SQL query:

 static void ViewGeneratedSQL() { NorthwindEntities NWEntities = new NorthwindEntities(); IQueryable<Product> beverages = from p in NWEntities.Products where p.Category.CategoryName == "Beverages" orderby p.ProductName select ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required