How can I see the SQL created by Entity Framework?

entity-framework

Question

As the title says, how do I view the SQL generated by Entity Framework from within my code? I'm running into an error where the EF is crashing because a field is generated by the database (a DateTime field), and I thought I set it to know that the store is generating it via StoreGeneratedPattern, but it's still crashing, so I would like to see what exactly it's trying to push up to the database.

P.S. I've only been using EF for about an hour now... Switching from L2S.

1
10
3/13/2012 7:25:12 PM

Accepted Answer

Since you don't have Sql Profiler, your best choice would be LINQPad. You can use your existing assembly.

Click Add connection -> Use a typed data context from your own assembly -> Entity framework and select your dll.

You can write queries directly against your model (or copy-paste from your code). Select the SQL 'tab' under the query window to view the generated SQL code.

16
10/28/2010 6:54:55 AM

Popular Answer

You can use the Entity Framework Profiler (EFProf). It's not free, but there's a 30-day trial available. It does a lot more neat stuff besides showing you the SQL statements.



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