Rya*_*son 4 entity-framework asp.net-mvc-3 mvc-mini-profiler
我通过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;
          }
     }
| 归档时间: | 
 | 
| 查看次数: | 584 次 | 
| 最近记录: |