O'Reilly logo

WCF 4.5 Multi-Layer Services Development with Entity Framework 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

Viewing 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 use 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 ToString method and the second one is to use SQL Profiler.

Viewing SQL statements using ToString

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

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

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