2

I would like to be able to log long running entity framework linq queries so I can investigate what is being generated. I have found that having an Entity Framework linq query and if I hover my mouse over it in the Visual Studio debugger, it shows me a string representation of the generated SQL that the entity framework will send to the SQL server.

I am wondering how it would be possible to get this string so I could print it out to a log file?

1
  • you also can use Linqpad, which supports to generate sql from your dbcontext Commented Mar 13, 2013 at 19:42

2 Answers 2

3

Did you try ToString();

var query = context.Products.Where(p=>p.IsActive);
var queryText = query.ToString();
Sign up to request clarification or add additional context in comments.

1 Comment

Wow... no I had not! I had read that it didn't work, though that was for an earlier version of the framework than what I am using. That should work perfectly - thanks!
0

Take a look at this logging provider for Entity Framework

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.