如何首先使MVC-mini-profiler在EF 4.1数据库上工作 [英] How to get MVC-mini-profiler working on EF 4.1 Database First

查看:97
本文介绍了如何首先使MVC-mini-profiler在EF 4.1数据库上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为此花了一天的大部分时间进行梳理。这是设置

Spent better part of the day combing through SO for this. Here's the setup


  • MVC 3应用程序,它使用存储库模式以及跨2个数据库的3个存储库。

  • EF 4.1首先对两个数据库连接使用 DBContext API

  • 从nuget安装了mvc-mini-profiler

这是我在存储库中创建Db上下文的方式

This is how I create my Db Context in the repository

public class TransactionRepository : BaseRepository, ITransactionRepository
{
    AccountingEntities _db = new AccountingEntities();

    // repository methods
}

然后在控制器中

public class InvoiceController : BaseController
{
    private ITransactionRepository _txnRepository;

    public InvoiceController()
    {
        _txnRepository = new TransactionRepository();
    }

    public InvoiceController(ITransactionRepository t)
    {
        _txnRepository = t;
    }
}

最后,我已经添加到web.config

Finally, I've added to web.config

  <system.data>
    <DbProviderFactories>
      <remove invariant="MvcMiniProfiler.Data.ProfiledDbProvider" />
      <add name="MvcMiniProfiler.Data.ProfiledDbProvider" invariant="MvcMiniProfiler.Data.ProfiledDbProvider" description="MvcMiniProfiler.Data.ProfiledDbProvider" type="MvcMiniProfiler.Data.ProfiledDbProviderFactory, MvcMiniProfiler, Version=1.8.0.0, Culture=neutral, PublicKeyToken=b44f9351044011a3" />
    </DbProviderFactories>
  </system.data>

分析这些连接的下一步是什么?慢慢来吧,因为这是我第一次接触Entity Framework,所以对EF连接/上下文详细信息应该很少假设。

What are the next steps to profile these connections? Walk me slowly as this is my first exposure to Entity Framework, so assume very little about EF connection/context details.

推荐答案

I重新编写了拦截代码,因此它更健壮。

I rewrote the interception code so it is way more robust.


  1. nuget MiniProfiler.EF(版本1.9.1)

  2. 在App初始化运行期间: MiniProfilerEF.Initialize();

  1. nuget MiniProfiler.EF (version 1.9.1)
  2. During App Init run: MiniProfilerEF.Initialize();

这篇关于如何首先使MVC-mini-profiler在EF 4.1数据库上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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