实体框架 – 具有实体框架的MVC MiniProfiler 5模型第一个错误:无法确定提供程序名称

使用实体框架5,MiniProfiler 2. Nuget安装MiniProfiler.EF.

创建连接如下

var conn = new EFProfiledDbConnection(DbConnections.GetsqlConnection(),MiniProfiler.Current);
return new MyDbContext(conn,true);

当尝试使用DbContext检索数据时,将返回以下错误

Unable to determine the provider name for connection of type     
'StackExchange.Profiling.Data.EFProfiledDbConnection'.`

我已经尝试将以下内容添加到web.config中:

<system.data>
  <DbProviderFactories>
    <remove invariant="StackExchange.Profiling.Data.ProfiledDbProviderFactory" />
    <add name="StackExchange.Profiling.Data.ProfiledDbProviderFactory" 
         invariant="StackExchange.Profiling.Data.ProfiledDbProviderFactory" 
         description="StackExchange.Profiling.Data.ProfiledDbProviderFactory"
         type="StackExchange.Profiling.Data.ProfiledDbProviderFactory,MiniProfiler,Version=2.0.2.0,Culture=neutral,PublicKeyToken=b44f9351044011a3" />
  </DbProviderFactories>
</system.data>

这没有帮助.我也尝试过使用MiniProfiler.EntityFramework中不同的EFProviderFactories的变体,但是无法让任何一个工作.

如果我尝试运行MiniProfilerEF.Initialize();在App_Start中,当尝试访问DB时,我会收到以下错误消息:

Code generated using the T4 templates for Database First and Model First development may not work correctly if used in Code First mode. To continue using Database First or Model First ensure that the Entity Framework connection string is specified in the config file of executing application. To use these classes,that were generated from Database First or Model First,with Code First add any additional configuration using attributes or the DbModelBuilder API and then remove the code that throws this exception.

从web.config删除DbProviderFactories部分并运行MiniProfilerEF.Initialize_EF42();在App_Start中导致原始错误.

由于MiniProfiler页面说MiniProfilerEF.Initialize()仅用于代码,这似乎不是要走的路.

其他搜索没有给我任何其他的东西要尝试,除了添加到Web.Config的部分.有关如何进行的建议?目标是能够使用Mvc MiniProfiler分析的Model First DbContext.

解决方法

你的global.asax看起来像这样吗?
public class MvcApplication : HttpApplication
{
    protected void Application_Start()
    {
        AreaRegistration.RegisterallAreas();

        WebApiConfig.Register(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
        AuthConfig.Registerauth();
        AutomapperConfig.RegisterMappings();

        MiniProfiler.Settings.sqlFormatter = new StackExchange.Profiling.sqlFormatters.sqlServerFormatter();
        MiniProfilerEF.Initialize();
    }

    protected void Application_BeginRequest()
    {
        if (Request.IsLocal)
        {
            MiniProfiler.Start();
        }
    }

    protected void Application_EndRequest(object sender,EventArgs e)
    {
        MiniProfiler.Stop(false);
    }
}

我定期实例化我的上下文:

var _database = new DinoContext(_connectionString);

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....