gpt4 book ai didi

entity-framework - MiniProfiler 设置 - 调用 'get_ProviderFactory' 方法后返回空值

转载 作者:行者123 更新时间:2023-12-04 04:39:14 30 4
gpt4 key购买 nike

经过数小时的努力,MiniProfiler 使其分析数据库查询,我没有运气,我收到错误:

A null was returned after calling the 'get_ProviderFactory' method on a store provider instance of type 'StackExchange.Profiling.Data.ProfiledDbConnection'. The store provider might not be functioning correctly.



我通过了很多 SO 帖子,但到目前为止没有任何效果,例如 this帖子是关于相同的错误,但具有不同的配置,而且没有答案。现在我知道 ProfiledDbConnection不覆盖 DbProviderFactory它是父类 DbConnectionDbProviderFactory 的实现中返回 null所以错误是可以预料的,但它应该以某种方式起作用。有一个 MiniProfilerEF.Initialize()但它似乎只能用于 CodeFirst,而我正在使用 DatabaseFirst 方法。

我已经安装了 MiniProfiler、MiniProfiler.EF、MiniProfilerMVC3 nuget 包。这是我的代码:
        string connectionString = ConfigurationManager.ConnectionStrings["SqlConnection"].ConnectionString;
var sqlConnection = new SqlConnection(connectionString);
var profiled = new ProfiledDbConnection(sqlConnection, MiniProfiler.Current);
var db = new DbContext(profiled, true);
db.Set<Customer>().ToList();

我正在使用 asp.net mvc4、EF5、DatabseFirst、MiniProfiler 2.1.0.0、Sql Server

有什么想法吗?

最佳答案

因此,来自您对 Setup of mvc-mini-profiler for EF-db- first 的评论,您是否尝试删除 Mini Profiler 特定的包装器?

var profiled = new ProfiledDbConnection(sqlConnection, MiniProfiler.Current);
var db = new DbContext(profiled, true);
db.Set<Customer>().ToList();
相反,只需添加
protected void Application_Start()
{
// any other code
MiniProfilerEF.Initialize();
}
然后进行标准的数据库访问?
using (var db = new WordsEntities()) {
var posts = db.Customer.Take(4);
// more code
}

关于entity-framework - MiniProfiler 设置 - 调用 'get_ProviderFactory' 方法后返回空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19195200/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com