开发者

Viewing Entity SQL produced by Linq-to-Entities

开发者 https://www.devze.com 2023-02-14 05:17 出处:网络
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?)

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!


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.


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());


To view linq query in development environment.

  1. You assign your query in IQueryable variable.
  2. Plase debug point below the query in next line. So, Query get executed.
  3. Place mouse over the IQueryable variable. You will be able to see the SQL query.
  4. You can copy your sql query in SQL query analyser and execute it.

view example in image http://i.stack.imgur.com/t6PK6.png

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号