gpt4 book ai didi

asp.net-mvc - 使用 MvcMiniProfiler 分析 Entity Framework

转载 作者:行者123 更新时间:2023-12-01 09:59:10 25 4
gpt4 key购买 nike

我有一个 Asp.net Mvc 3 应用程序,它现在正在使用 MvcMiniProfiler。我还使用 Entity Framework 来访问我的数据库,并且我想让探查器能够使用实体模型。到目前为止,我已经在下面创建了上下文工厂:

internal class ProfiledContextFactory : IContextFactory
{
public ModelContainer GetContext()
{
var conn = ProfiledDbConnection.Get(GetConnection());
return ObjectContextUtils.CreateObjectContext<ModelContainer>(conn);
}

private static EntityConnection GetConnection()
{
return new EntityConnection(ConfigurationManager.ConnectionStrings["ModelContainer"].ConnectionString);
}
}

当我运行上面的代码(当我开始一个工作单元时由我的存储库层调用)时,它在调用 MvcMiniProfiler.ProfiledDbServices 类中的 CreateDbCommandDefinition 时陷入无限循环。

有什么线索是我做错了吗?

最佳答案

问题是我的 GetConnection 返回的是 EntityConnection,而不是 EntityConnection 中的 SqlConnection。我现在修改了我的代码,使其显示为:

private static SqlConnection GetConnection()
{
var connStr = ConfigurationManager.ConnectionStrings["ModelContainer"].ConnectionString;
var entityConnStr = new EntityConnectionStringBuilder(connStr);
return new SqlConnection(entityConnStr.ProviderConnectionString);
}

而且效果很好。

我在看这个问题时发现了这一点:Using mvc-mini-profiler with EF 4.0 and Ninject

关于asp.net-mvc - 使用 MvcMiniProfiler 分析 Entity Framework ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6443398/

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