我想使用MVC Mini Profiler进行实体框架连接。我这样做的方式是这样的:
public static XXXXX.DAL.BO.XXXXXEntities GetEntityConnection()
{
var conn = ProfiledDbConnection.Get(new EntityConnection(ConfigurationManager.ConnectionStrings["XXXXXEntities"].ConnectionString));
return ObjectContextUtils.CreateObjectContext<XXXXX.DAL.BO.XXXXXEntities>(conn);
}
因此,以下行是为其余代码获取Context:
XXXXX.DAL.BO.XXXXXEntities ctx = GetEntityConnection();
但是,当我尝试在浏览器上查看此站点时,WebDev.WebServer40.exe崩溃了。
有谁知道为什么?
谢谢你。
P.S。 以前是
XXXXX.DAL.BO.XXXXXEntities ctx = new XXXXX.DAL.BO.XXXXXEntities();
它工作正常。
答案 0 :(得分:1)
如果您能够将v3.0.10 nuget用于EF6,那么您需要做的就是连接实体框架
protected void Application_Start()
{
MiniProfilerEF6.Initialize();
}
使用EF 5或更早版本(使用相应的nuget包)将要求您生成EFProfiledDbConnection
,正如Anirudh在他的回答中所写:
var conn = new EFProfiledDbConnection(GetConnection(), MiniProfiler.Current);
return ObjectContextUtils.CreateObjectContext<MyModel>(conn);
答案 1 :(得分:0)
尝试将您的连接初始化为:
connection = new EFProfiledDbConnection( new EntityConnection(ConfigurationManager.ConnectionStrings["XXXXXEntities"].ConnectionString),
MiniProfiler.Current);
适合我。