Profile EntityFramework [英] Profile EntityFramework

查看:152
本文介绍了Profile EntityFramework的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下示例代码:

  Context context = new Context();
  Repository repository = new Repository(context);

  Post post = repository.First<Post>(x => x.Id == 1);

  Model model = new Model {
    Created = cube.Created,
    Id = cube.Id,
    Name = cube.Name,
    Pack = cube.Pack.Id,
    Mimes = context.Files.Where(x => x.Id == 1).Select(x => x.Mime).ToList()
  };

我需要找到发送到数据库的SQL查询。

I need to find which SQL queries are being sent to the database.

如何使用SQL Express和VS 2012配置EF查询?

How can I profile the EF queries using SQL Express and VS 2012?

是否有任何工具?

推荐答案

您有几个选项。


  1. 检查通过使用((ObjectQuery)查询)在运行时打印查询).ToTraceString()请参阅 https://stackoverflow.com/a/7901917/1070291 (我认为这只适用于查询,所以在上述情况下可能不是最好的)

  2. 使用SQL管理工作室内的分析器

  3. 使用实体框架分析器(一个非常好的第三方工具,具有试用版,这是我用来分析查询)

  1. Examine the query by printing it at runtime using ((ObjectQuery)query).ToTraceString() see https://stackoverflow.com/a/7901917/1070291 (I think this only works for queries so may not be the best in the above scenario)
  2. Use SQL Profiler which is built into management studio
  3. Use Entity Framework Profiler (a very good third party tool with a trial version, this is what I use to analyse queries)

这篇关于Profile EntityFramework的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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