tabs ↹ over ␣ ␣ ␣ spaces

by Jiří {x2} Činčura

How to show SQL command created by Entity Framework?

26 May 2008 1 mins .NET, Entity Framework, LINQ

Updated version.

Sometimes you may need to look at the command, that’s created from your i.e. LINQ query and sent to database. Let’s say you have query like this:

var q = from m in e.master select m.t.Length;

You can cast the q into ObjectQuery and use the ToTraceString method to see the query:

Console.WriteLine(((ObjectQuery)q).ToTraceString());

This will show you the query, that’s sent to store you’re using (mainly relational database). Neat and easy.

Profile Picture Jiří Činčura is .NET, C# and Firebird expert. He focuses on data and business layers, language constructs, parallelism, databases and performance. For almost two decades he contributes to open-source, i.e. FirebirdClient. He works as a senior software engineer for Microsoft. Frequent speaker and blogger at www.tabsoverspaces.com.