Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Viewing Entity SQL produced by Linq-to-Entities

Is there a way I can view the Entity Sql (eSQL) that my Linq-to-entities queries are generating with EF framework (that is, not native SQL, but eSQL, if that makes sense?)

Thanks!

like image 916
Sean Avatar asked Mar 02 '11 18:03

Sean


2 Answers

You can't. It is not generated.
Actually, LINQ to Entities queries are translated directly into Expression Tree, and the nodes of this Expression Tree are translated into SQL clauses, and then integrated into a SQL query. No Entity SQL.

like image 115
Devart Avatar answered Sep 30 '22 11:09

Devart


var query1 = from person in Database
           select person.Name;

You can cast the query1 into ObjectQuery and use the ToTraceString method to see the query.

Console.WriteLine(((ObjectQuery)query1).ToTraceString());
like image 41
Somedeveloper Avatar answered Sep 30 '22 12:09

Somedeveloper