How do I view the SQL generated by the Entity Framework?

后端 未结 22 2825
别那么骄傲
别那么骄傲 2020-11-21 05:35

How do I view the SQL generated by entity framework ?

(In my particular case I\'m using the mysql provider - if it matters)

22条回答
  •  感情败类
    2020-11-21 06:23

    You can do the following:

    IQueryable query = from x in appEntities
                 where x.id == 32
                 select x;
    
    var sql = ((System.Data.Objects.ObjectQuery)query).ToTraceString();
    

    or in EF6:

    var sql = ((System.Data.Entity.Core.Objects.ObjectQuery)query)
                .ToTraceString();
    

    That will give you the SQL that was generated.

提交回复
热议问题