MiniProfiler 与 EF“模型优先” EDMX模型

发布于 2024-11-26 12:41:05 字数 699 浏览 3 评论 0原文

我正在尝试让 MiniProfiler 分析我的数据库访问,但遇到了问题。我看到的所有帮助似乎都是针对“代码优先”实体框架连接。我的模型是在今年代码首次更新可用之前设计的,我使用设计器创建了 edmx 模型。 (我已经使用它近一年了,它似乎对我有用)

MiniProfiler 文档网站上的示例对我来说没有意义。我尝试了一些变体,但遇到了问题。

我的模型称为 CYEntities,通常要实例化一个 ObjectContext 我只是这样做 var context = new CYEntities() 这是我为探查器所做的尝试...

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. 

这会引发异常...

System.ArgumentException:无法找到请求的 .Net Framework 数据提供程序。它可能未安装。

我不知道该去哪里。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一场信仰旅途 2024-12-03 12:41:05

尝试这样:

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);

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);
墨落画卷 2024-12-03 12:41:05

我也有同样的问题。看来您必须将以下内容添加到您的 web.config 中,但是,对我来说,这会导致 w3wp.exe 进程崩溃(以及 Visual Studio 中的 Web 服务器,用于本地请求)。这似乎不会发生在其他人身上,因此它可能对您有用(请确保插入您正在使用的探查器的实际版本)。

<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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文