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

后端 未结 22 3213
别那么骄傲
别那么骄傲 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:17

    In my case for EF 6+, instead of using this in the Immediate Window to find the query string:

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

    I ended up having to use this to get the generated SQL command:

    var sql = ((System.Data.Entity.Infrastructure.DbQuery<<>f__AnonymousType3>)query).ToString();
    

    Of course your anonymous type signature might be different.

    HTH.

提交回复
热议问题