Tue. Dec 10th, 2019

Samir Daoudi's Technical Blog

SharePoint, Office 365, C#, .Net, SQL Server News, Tips, Ebooks, Events, Webinars ….etc

Display SQL Query used by entity framework

Sometimes you may need to look at the command, that's created from your i.e LINQ query and sent to database var q = from m in e.master You can cast the q into ObjectQuery and use the ToTraceString method to see the query:

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:

1
2
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:

1
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.

Leave a comment

Copyright © All rights reserved. | Newsphere by AF themes.
Show Buttons
Hide Buttons

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.