如何查看实体框架生成的 SQL? [英] How do I view the SQL generated by the Entity Framework?

查看:26
本文介绍了如何查看实体框架生成的 SQL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何查看实体框架生成的SQL?

How do I view the SQL generated by entity framework ?

(在我的特殊情况下,我使用的是 mysql 提供程序 - 如果重要的话)

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

推荐答案

您可以执行以下操作:

IQueryable query = from x in appEntities
             where x.id == 32
             select x;

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

或在 EF6 中:

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

或在 EF6.3+ 中:

or in EF6.3+:

var sql = ((dynamic)flooringStoresProducts).Sql;

这会给你生成的 SQL.

That will give you the SQL that was generated.

这篇关于如何查看实体框架生成的 SQL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆