How can I get the sql script generated by an entity framework query? i.e. If I write
entityDataDontext.table1.Where(r => r.primarykey == 1).First();
then how can I get the SQL which should be somewhat like this:
select * from table1 where primarykey = 1
Thanks in advance :)
To view the SQL that will be generated, simply call ToTraceString() . You can add it into your watch window and set a breakpoint to see what the query would be at any given point for any LINQ query. You can attach a tracer to your SQL server of choice, which will show you the final query in all its gory detail.
When you're going against SQL Server as your backend database, SQL Server Profiler is always the best tool to see exactly what SQL statements are being sent to your database to be processed.
See Introducting SQL Server Profiler for background info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With