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 p; NWEntities.Dispose(); }
As we have learned from the previous section the variable, beverages
, is of the type...