Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the sql generated by the entity framework [duplicate]

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 :)

like image 773
Gaurav Pandey Avatar asked Jan 15 '11 15:01

Gaurav Pandey


People also ask

How can I see the SQL statement generated by Entity Framework?

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.


1 Answers

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.

like image 173
marc_s Avatar answered Oct 24 '22 23:10

marc_s