MiniProfiler with EF “model first” edmx model

两盒软妹~` 提交于 2019-11-29 00:53:18

问题


I'm trying to get MiniProfiler to profile my database access but I'm running into problems. All the help I see out there seems to be for "code first" entity framework connections. My model was designed before the code first update was available this year and I used the designer to create the edmx model. (I've been using this for almost a year and it seems to be working for me)

The example on the MiniProfiler documentation site doesn't make sense to me. I've tried a few variations of it but I'm having problems.

My Model is called CYEntities, normally to instantiate an ObjectContext I just do this var context = new CYEntities() here's what I've tried for the profiler...

var dbConnection = new CYEntities().Connection;
var profiledConnection = ProfiledDbConnection.Get(dbConnection);
var context = profiledConnection.CreateObjectContext<CYEntities>(); // this is the context I'd finally use to access data. 

This throws an exception...

System.ArgumentException: Unable to find the requested .Net Framework Data Provider. It may not be installed.

I'm not sure where to go from here.


回答1:


I'm having the same issue. It appears that you must add the following to your web.config, however, for me this causes the w3wp.exe process to crash (and the web server in visual studio, for local requests). It doesn't seem like something that is happening to anyone else, so it might work for you (make sure to insert the actual version of the profiler you are using).

<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.7.0.0, Culture=neutral, PublicKeyToken=b44f9351044011a3" />
  </DbProviderFactories>
</system.data>



回答2:


Try like this:

var connectionString = ConfigurationManager
    .ConnectionStrings["MyConnectionString"]
    .ConnectionString;
var ecsb = new EntityConnectionStringBuilder(connectionString);
var sqlConn = new SqlConnection(ecsb.ProviderConnectionString);
var pConn = ProfiledDbConnection.Get(sqlConn, MiniProfiler.Current);
var context = ObjectContextUtils.CreateObjectContext<CYEntities>(pConn);


来源:https://stackoverflow.com/questions/6802855/miniprofiler-with-ef-model-first-edmx-model

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