在使用MiniProfiler进行数小时数据库查询后,我没有运气,我收到了错误:
在调用'get_ProviderFactory'方法后返回null 类型的商店提供程序实例 'StackExchange.Profiling.Data.ProfiledDbConnection'。商店 提供商可能无法正常运作。
我通过了很多SO帖子,但到目前为止没有任何工作,例如this帖子,它有相同的错误,但配置不同,而且没有答案。现在我知道ProfiledDbConnection
没有覆盖DbProviderFactory
,它的父类DbConnection
在它的DbProviderFactory
实现中返回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
任何想法?
答案 0 :(得分:2)
所以,从您对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
}