How to get MVC-mini-profiler working on EF 4.1 Database First

大城市里の小女人 提交于 2019-12-24 00:14:12

问题


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

  • MVC 3 App using Repository pattern with 3 repositories across 2 databases.
  • EF 4.1 Database first using the DBContext API for both db connections.
  • Installed mvc-mini-profiler from nuget

This is how I create my Db Context in the repository

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

    // repository methods
}

Then in controllers

public class InvoiceController : BaseController
{
    private ITransactionRepository _txnRepository;

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

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

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>

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.


回答1:


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

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


来源:https://stackoverflow.com/questions/7212926/how-to-get-mvc-mini-profiler-working-on-ef-4-1-database-first

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!