source - http://www.mortenanderson.net/logging-sql-statements-in-entity-framework
If you want to see how your LINQ query is going to look like when tranformed into SQL all you have to do is call ToString() on your IQueryable
Running the example below
Will output
If you want to see how your LINQ query is going to look like when tranformed into SQL all you have to do is call ToString() on your IQueryable
Running the example below
JavaScript:
using (var context = new PersonDbContext())
{
var query = context.Persons.Where(x => x.Age == 34);
Console.WriteLine(query.ToString());
}
Will output
JavaScript:
SELECT
[Extent1].[Id] AS [Id],
[Extent1].[FirstName] AS [FirstName],
[Extent1].[LastName] AS [LastName],
[Extent1].[Age] AS [Age]
FROM [dbo].[People] AS [Extent1]
WHERE 34 = [Extent1].[Age]