Retrieve LINQ to sql statement (IQueryable) WITH parameters

You can also see the generated sql query if you have an instance of
IQueryable<T> and call the .ToString() method.
For Example:

var db = new DbContext();
IQueryable<Blog> query = db.Blog.Where(tt=> tt.Id > 100).OrderByDescending(tt=>tt.Id);
var sqlString = query.ToString();
Console.WriteLine(sqlString);

This will generate an output of:

SELECT [Extent1].[Id] AS [Id], 
[Extent1].[Title] AS [Title], 
[Extent1].[Author] AS [Author], 
[Extent1].[Text] AS [Text], 
[Extent1].[CreatedAt] AS [CreatedAt], 
[Extent1].[UpdatedAt] AS [UpdatedAt]
FROM [dbo].[Blogs] AS [Extent1]
WHERE [Extent1].[Id] > 100
ORDER BY [Extent1].[Id] DESC

Leave a Comment