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

前端之家收集整理的这篇文章主要介绍了实体框架 – 具有实体框架的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);
原文链接:https://www.f2er.com/aspnet/250104.html

猜你在找的asp.Net相关文章