【问题标题】:generate sql query from entity framework从实体框架生成 sql 查询
【发布时间】:2012-03-09 12:13:30
【问题描述】:

我正在尝试在实体框架 3,5 中使用 .ToTraceString() 生成 sql 查询; 但我收到以下错误

无法将类型“System.Collections.Generic.List”转换为“System.Data.Objects.ObjectQuery”

我有以下代码 我需要生成sql查询

                  customers= ent.Customer
                      .Include("UserType")
                      .Include("User")
                      .Where(c => c.Enabled == true)
                  .ToList<Customer>();

如何获取实体框架生成的sql查询。我没有 sql profiler。

非常感谢

【问题讨论】:

    标签: c#


    【解决方案1】:

    在调用 ToTraceString() 之前尽量不要调用 ToList(),因为这样做时返回的列表没有 ToTraceString() 方法

    【讨论】:

      猜你喜欢
      • 2014-01-25
      • 1970-01-01
      • 2017-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-26
      相关资源
      最近更新 更多