Support for EF6?


#1

Is there official support for EF6 ?

I manually build the EF6 version and it seems it’s working. Is there also a NuGet package available yet ?


#2

Just released a beta nuget for EF6.


#3

Would it be possible to get some information about how to install / use the MiniProfiler with EF6 ?

In the old version content was added to the layout page, there was a class in the App_Startup folder etc.

When installing MiniProfiler.EF6 nothing is added or altered. I can see there is still Start() Stop() methods and the EF6 have a Initialize method.
But using the old code there is missing a ProfilingActionFilter and ProfilingViewEngine.


#4

To initialize EF6, all you need to do is:

protected void Application_Start()
{
    MiniProfilerEF6.Initialize();
}

MiniProfiler never added files to App_Startup. You may be thinking about the files that the MiniProfiler.MVC3 package added. Those are still in github it you want to reference them, but starting with the MiniProfiler.MVC4 package these are no longer added. Setup is up to you to do in Global.asax.cs. See MiniProfiler.com for more instructions on how to do this.


#5

Thanks for the quick reply.
I totally forgot that there were also a MiniProfiler.MVC package which is the one that installed the config part.

But when trying to debug I now get an exception thrown when initializing the database.

“An exception of type ‘System.Data.SqlClient.SqlException’ occurred in System.Data.dll but was not handled in user code. Additional information: Invalid column name ‘ContextKey’.”

I am able to skip past the exception.
At first it I think the exception was something about it couldn’t cast ProfiledDbConnection or something, but it hasn’t come up with that exception since the first time i ran it (it asked be to locate the file on my computer - open file dialog).

If I disable the MiniProfiler it works without any exceptions.


#6

You are using MiniProfiler.EF6?

Do you have any info on what file/line number the error occurs?

If you F5 past the exception, does everything run as normal or is MiniProfiler and/or data retrieval not working?


#7

Yes i am using MiniProfiler.EF6.

The Exception is thrown when calling this - dbContext.Database.Initialize(force: false);

  System.Data.SqlClient.SqlException was unhandled by user code
  HResult=-2146232060
  Message=Invalid column name 'ContextKey'.
  Source=.Net SqlClient Data Provider
  ErrorCode=-2146232060
  Class=16
  LineNumber=6
  Number=207
  Procedure=""
  Server=(LocalDB)\v11.0
  State=1
  StackTrace:
       at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
       at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
       at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
       at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
       at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
       at System.Data.SqlClient.SqlDataReader.get_MetaData()
       at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
       at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)
       at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
       at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
       at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
       at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
       at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
       at StackExchange.Profiling.Data.ProfiledDbCommand.ExecuteDbDataReader(CommandBehavior behavior) in d:\Files\GitHub\miniprofiler\dotnet\StackExchange.Profiling\Data\ProfiledDbCommand.cs:line 233
       at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
       at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<>c__DisplayClassb.<Reader>b__8()
       at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TInterceptionContext,TResult](Func`1 operation, TInterceptionContext interceptionContext, Action`1 executing, Action`1 executed)
       at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)
       at System.Data.Entity.Internal.InterceptableDbCommand.ExecuteDbDataReader(CommandBehavior behavior)
       at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
       at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
  InnerException: 

Everything seems to run fine when I skip past the exceptions.
It works when running in IIS.


#8

This looks like a known issue with EF6 that happens on the first db call to a code first db that had been created with EF5, that only shows up when running in debug mode. MS has closed the issue and will not be fixing it. So it looks like an EF6 bug, not a MiniProfiler bug, and it doesn’t affect anything and only runs in debug.

I just pushed a commit to swallow this specific Exception when it is encountered in EF6.Initialize. Just pushed EF6 3.0.10-beta4 to nuget which includes this fix.