Asp.net mvc 3 无法使用Enity Framework 4.0设置MiniProfiler(不是先编码)
我通过nuget在我的项目中安装了MiniProfiler和MiniProfiler.EF 在使用MiniProfiler之前,我会在我的模型存储库中使用以下内容打开连接:Asp.net mvc 3 无法使用Enity Framework 4.0设置MiniProfiler(不是先编码),asp.net-mvc-3,entity-framework,mvc-mini-profiler,Asp.net Mvc 3,Entity Framework,Mvc Mini Profiler,我通过nuget在我的项目中安装了MiniProfiler和MiniProfiler.EF 在使用MiniProfiler之前,我会在我的模型存储库中使用以下内容打开连接: public class NotificationRepository { private CBNotificationModel.CB_NotificationEntities db; public NotificationRepository() {
public class NotificationRepository
{
private CBNotificationModel.CB_NotificationEntities db;
public NotificationRepository()
{
db = new CB_NotificationEntities();
}
public NotificationContact GetNotificationContacts()
{
return db.NotificationContacts.ToList();
}
}
要使用我创建的迷你探查器,请执行以下操作:
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);
}
}
但是,这会产生错误:
mscorlib.dll中发生类型为“System.StackOverflowException”的未处理异常
我漏了一步吗?我尝试在应用程序_start()中添加MiniProfilerEF.Initialize()和MiniProfilerEF.Initialize_EF42(),但这只会更改给定的错误
对于设置实体框架项目以使用miniprofiler,似乎没有太多的信息,除非它是codefirst。通过将我的ConnectionHelper类更改为以下内容,我能够实现这一点:
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;
}
}
公共静态类ConnectionHelper
{
公共静态CB_NotificationEntities GetEntityConnection()
{
var connectionString=ConfigurationManager.connectionString[“CB_NotificationEntities”]。connectionString;
var ecsb=新的EntityConnectionStringBuilder(connectionString);
var sqlConn=新的SqlConnection(ecsb.ProviderConnectionString);
var pConn=new StackExchange.profileing.Data.EFProfiledDbConnection(sqlConn,MiniProfiler.Current);
var context=ObjectContextTILS.CreateObjectContext(pConn);
返回上下文;
}
}
我希望我能给你这么多的分数,我到处找了这个哦,是的,谢谢你。这是我第二次尝试让MiniProfiler工作,每次我都收到StackOverflowException。这个解决方案非常有效。
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;
}
}