EF 其他版本:EntityFramework 如何查看执行的 SQL 代码?

在 EF7 中,并没有 Context.Database.Log 属性访问方式,但改变更加强大了,我们可以使用下面方式配置:

public void ContextLoad_Test()
{
    using (var context = new BloggingContext())
    {
        var query = from b in context.Blogs
                           select b;

        //AddProvider 增加日志“提供商”
        context.Configuration.LoggerFactory.AddProvider(new DiagnosticsLoggerProvider(
                new SourceSwitch("SourceSwitch", "Verbose"),
                new ConsoleTraceListener()));

        var result = query.OrderBy(b => b.BlogId * 2).ThenBy(b => b.BlogCateId).Skip(0).Take(100).ToList();
    }
}

Output 窗口输出:

EntityFramework 7 如何查看执行的 SQL 代码?

参考资料:

相关文章:

  • 2021-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-15
  • 2021-08-16
  • 2021-10-07
猜你喜欢
  • 2021-09-14
  • 2021-08-06
  • 2022-01-09
  • 2021-12-06
  • 2021-06-23
相关资源
相似解决方案