Using mvc-mini-profiler database profiling with Entity Framework Code First

后端 未结 3 1148
醉酒成梦
醉酒成梦 2020-11-27 18:32

I\'m using the mvc-mini-profiler in my project built with ASP.Net MVC 3 and Entity Framework code-first.

Everything works great until I attempt to add database prof

相关标签:
3条回答
  • 2020-11-27 18:55

    I was still having problems getting this to work and found that I needed to rename or remove the connection string to get Database.DefaultConnectionFactory to work.

    Please refer to this answer for more detail.

    0 讨论(0)
  • 2020-11-27 19:08

    This is now fully supported, check out the latest source or grab the package from nuget.

    You will need the MiniProfiler.EF package if you are using nuget. (1.9.1 and up)

    Supporting this involved a large set of modifications to the underlying proxy object to support acting as EF code first proxies.

    To add this support:

    During your Application_Start run:

    MiniProfilerEF.Initialize();

    Note: EF Code First will store table metadata in a table called: EdmMetadata. This metadata uses the provider as part of the entity key. If you initialized your provider as a non-profiled provider, you will have to re-build this metadata. Deleting all the rows from EdmMetadata may do the trick, alternatively some smarter providers are able to handle this transparently.

    0 讨论(0)
  • 2020-11-27 19:12

    This error in my experience has always been an invalid connection string, or a lack of connection to the DB, like "A network service error occurred while connecting...".

    Also note that the DbContext just needs the "connectionStringKey" in the constructor, like

    public MyDbContext() : 
         base("MyConnectionName", true)
        { }
    
    0 讨论(0)
提交回复
热议问题