First, trace the SQL query in EF Code.

asp.net-mvc c# entity-framework sql

Question

I'm using Entity Framework Code First and I'd like to be able to record all the SQL queries generated by the DbContext. In Linq to sql there was a DB log and I can't seem to find it in EF. I could then drop them in a log or output it to the page.

I'm using the version 4.1.0.0 of the EntityFramework Assembly.

1
18
3/15/2013 5:05:30 AM

Popular Answer

Your best bet would be to use the Entity Framework Profiler, although it's unfortunately not free.

You can also manually get the SQL it will generate by running a ToString() on the IQueryable itself, but that will have to be done on a per-query basis.

One final option is that if you are using MS Sql Server as your backend, you can load up the Sql Server Profiler (that comes with Sql Server Management Studio I believe) and log the sql statements from there.

6
5/29/2011 3:41:55 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow