Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 使用MvcMiniProfiler分析实体框架_Asp.net Mvc_Asp.net Mvc 3_Entity Framework_Mvc Mini Profiler - Fatal编程技术网

Asp.net mvc 使用MvcMiniProfiler分析实体框架

Asp.net mvc 使用MvcMiniProfiler分析实体框架,asp.net-mvc,asp.net-mvc-3,entity-framework,mvc-mini-profiler,Asp.net Mvc,Asp.net Mvc 3,Entity Framework,Mvc Mini Profiler,我有一个Asp.net Mvc 3应用程序,现在正在使用MvcMiniProfiler。我还使用实体框架来访问我的数据库,我想让探查器能够使用实体模型。到目前为止,我已经创建了以下上下文工厂: internal class ProfiledContextFactory : IContextFactory { public ModelContainer GetContext() { var conn = ProfiledDbConnection.Get(GetCon

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

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);
    }
}
内部类ProfiledContextFactory:IContextFactory
{
公共ModelContainer GetContext()
{
var conn=ProfiledDbConnection.Get(GetConnection());
返回ObjectContextTILS.CreateObjectContext(conn);
}
私有静态EntityConnection GetConnection()
{
返回新的EntityConnection(ConfigurationManager.ConnectionString[“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);
}
而且效果很好

我在看这个问题时发现了这一点: