asp.net-mvc-3 – 无法使用Enity Framework 4.0设置MiniProfiler
发布时间:2020-12-16 06:31:23 所属栏目:asp.Net 来源:网络整理
导读:我通过nuget在我的项目中安装了MiniProfiler和MiniProfiler.EF. 在使用MiniProfiler之前,我会在我的模型库中使用它来打开一个连接: public class NotificationRepository { private CBNotificationModel.CB_NotificationEntities db; public NotificationRe
我通过nuget在我的项目中安装了MiniProfiler和MiniProfiler.EF.
在使用MiniProfiler之前,我会在我的模型库中使用它来打开一个连接: 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); } } 模型库现在使用 db = ConnectionHelper.GetEntityConnection(); 但是这会给出错误: mscorlib.dll中发生了未处理的“System.StackOverflowException”类型异常 我错过了一步吗?我尝试在Application_start()中添加MiniProfilerEF.Initialize()和MiniProfilerEF.Initialize_EF42(),但这只会更改给定的错误. 设置实体框架项目以使用miniprofiler似乎没有太多信息,除非它是代码优先的. 解决方法
我能够通过将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; } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ASP.NET – 如何单元测试WebControls?
- asp.net-mvc – 具有预设值的Html.HiddenFor
- asp.net-mvc – ‘/’应用程序中的ASP.NET MVC3 / Razor服务
- asp.net – WebForm_DoCallback定义
- asp.net-mvc – 升级到.Net 4.5和osFamily 3后无法启动Azur
- oauth-2.0 – ASP.NET MVC 5中的自定义oAuth客户端
- asp.net-mvc-5 – 同一域中的Web API 2项目和MVC 5网站项目
- razor – MVC3到MVC4 RTM手动升级问题:@在此关键字前面抛出
- 在asp.net中制作某些页面的最佳方法是什么?需要登录?
- asp.net-mvc – ASP.NET MVC 1.0中的表单输入验证选项