Failed to configure MiniProfiler w / Enity Framework 4.0 (no code at first)

I installed MiniProfiler and MiniProfiler.EF in my project via nuget.

Before using MiniProfiler, I would open the 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 the 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 an error:

An unhandled exception of type "System.StackOverflowException" occurred in the mscorlib.dll file

Did I miss a step? I tried to add MiniProfilerEF.Initialize () and MiniProfilerEF.Initialize_EF42 () to Application_start (), but that will just change the errors given.

It seems that there is not much information about setting up an entity framework project to use miniprofiler if it is not code.

+4
source share
1 answer

I managed to get this working by changing the 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; } } 
+7
source

All Articles