LINQ to SQL follows the following three steps.
The simple way of viewing the generated SQL is to use the DataContext.Log
property to display SQL code in the console window before the code is executed.
using (var db = new CustomerContext(@"Data Source=(localdb)\ProjectsV13;Initial Catalog=CustomerContext;"))
{
db.Log = Console.Out;
var list = db.Customers.OrderBy(c => c.FirstName).ToList();
}
In this example, the Log property display the following generated SQL in the console window.
SELECT [t0].[CustomerId], [t0].[FirstName], [t0].[LastName], [t0].[Address]
FROM [Customers] AS [t0]
ORDER BY [t0].[FirstName]