gpt4 book ai didi

entity-framework - MVC MiniProfiler with Entity Framework 5 Model First Error : Unable to determine the provider name

转载 作者:行者123 更新时间:2023-12-03 22:35:57 28 4
gpt4 key购买 nike

使用 Entity Framework 5,MiniProfiler 2。为 MiniProfiler.EF 安装 Nuget。

创建连接如下

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 ,然后在尝试访问数据库时出现以下错误:

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.



删除 DbProviderFactories web.config 中的部分并运行 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);

关于entity-framework - MVC MiniProfiler with Entity Framework 5 Model First Error : Unable to determine the provider name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13959820/

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