问题描述
我通过我的NuGet安装项目和MiniProfiler MiniProfiler.EF。
I installed MiniProfiler and MiniProfiler.EF in my project via nuget.
使用MiniProfiler之前,我会在我的模型库中使用这种打开的连接:
Before using MiniProfiler I would open a connection using this in my model repository:
public class NotificationRepository
{
private CBNotificationModel.CB_NotificationEntities db;
public NotificationRepository()
{
db = new CB_NotificationEntities();
}
public NotificationContact GetNotificationContacts()
{
return db.NotificationContacts.ToList();
}
}
要使用我创建迷你探查:
To use mini profiler I created:
public static class ConnectionHelper
{
public static CB_NotificationEntities GetEntityConnection()
{
var conn = new StackExchange.Profiling.Data.EFProfiledDbConnection(GetConnection(), MiniProfiler.Current);
return ObjectContextUtils.CreateObjectContext<CB_NotificationEntities>(conn); // resides in the MiniProfiler.EF nuget pack
}
public static EntityConnection GetConnection()
{
return new EntityConnection(ConfigurationManager.ConnectionStrings["CB_NotificationEntities"].ConnectionString);
}
}
该模型库现在使用
The model repository now uses
db = ConnectionHelper.GetEntityConnection();
然而,这给出了错误:
However this gives the error:
类型'System.StackOverflowException未处理的异常出现在mscorlib.dll
An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll
我缺少的一个步骤?我尝试添加MiniProfilerEF.Initialize()和MiniProfilerEF.Initialize_EF42()中的Application_Start(),但是这只是改变给出的错误。
Am I missing a step? I tried adding MiniProfilerEF.Initialize() and MiniProfilerEF.Initialize_EF42() in Application_start() however that just changes the errors given.
似乎没有成为建立一个实体框架项目使用miniprofiler除非它是codefirst多的信息。
There does not seem to be much information for setting up a entity framework project to use miniprofiler unless it is codefirst.
推荐答案
我能够改变我的ConnectionHelper级以下得到这个工作:
I was able to get this working by changing my ConnectionHelper class to the following:
public static class ConnectionHelper
{
public static CB_NotificationEntities GetEntityConnection()
{
var connectionString = ConfigurationManager.ConnectionStrings["CB_NotificationEntities"].ConnectionString;
var ecsb = new EntityConnectionStringBuilder(connectionString);
var sqlConn = new SqlConnection(ecsb.ProviderConnectionString);
var pConn = new StackExchange.Profiling.Data.EFProfiledDbConnection(sqlConn, MiniProfiler.Current);
var context = ObjectContextUtils.CreateObjectContext<CB_NotificationEntities>(pConn);
return context;
}
}
这篇关于无法安装MiniProfiler W / Enity框架4.0(不code第一)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!