Search code examples
c#asp.net-mvcentity-frameworkmvc-mini-profiler

MiniProfiler plus EntityFramework plus EFProviderWrapperToolkit?


Is it possible to use the MiniProfiler 1.9 with EntityFramework and also with EFProviderWrapperToolkit? I'm also using the update edmx from database method, not code first.

I have EFProviderWrapperToolkit already installed and working very well, it's caching provider makes a big difference. But it seems to clash with the MiniProfiler:

protected void Application_BeginRequest()
{
    if (Request.IsLocal)
    {
        //MiniProfiler.Start();
        MiniProfilerEF.Initialize();
    }
}

It is probably because both MiniProfiler and EFProviderWrapperToolkit are attempting to wrap the db connection.

Gives this error message:

Unable to cast object of type 'MvcMiniProfiler.Data.EFProfiledDbConnection' to type 'EFProviderWrapperToolkit.DbConnectionWrapper'.

Line 229: DbProviderFactory factory = DbProviderFactories.GetFactory(invariantName); Line 230: var connectionWrapper = factory.CreateConnection(); Line 231: DbConnectionWrapper wrapper = (DbConnectionWrapper)connectionWrapper; Line 232: wrapper.WrappedConnection = connection; Line 233: connection = connectionWrapper;

[InvalidCastException: Unable to cast object of type 'MvcMiniProfiler.Data.EFProfiledDbConnection' to type 'EFProviderWrapperToolkit.DbConnectionWrapper'.] EFProviderWrapperToolkit.DbConnectionWrapper.WrapConnection(DbConnection connection, String[] wrapperProviderInvariantNames) in C:\src\MyApp.2010\EF4ProviderWrappers\EFProviderWrapperToolkit\DbConnectionWrapper.cs:231 EFProviderWrapperToolkit.EntityConnectionWrapperUtils.CreateEntityConnectionWithWrappers(String entityConnectionString, EntityConnectionStringBuilder ecsb, String[] wrapperProviders) in C:\src\MyApp.2010\EF4ProviderWrappers\EFProviderWrapperToolkit\EntityConnectionWrapperUtils.cs:60 MyApp.Infrastructure.Repository.EF.ExtendedMyAppContext..ctor(String connectionString, EntityConnectionStringBuilder ecsb) in C:\src\MyApp.2010\MyApp.Infrastructure.Repository.EF\ExtendedMyAppContext.cs:19 MyApp.Infrastructure.Repository.EF.ObjectContextManager.GetObjectContext() in C:\src\MyApp.2010\MyApp.Infrastructure.Repository.EF\Repository.EF\ObjectContextManager.cs:62 MyApp.Infrastructure.Repository.EF.GenericRepository1.get_ObjectContext() in C:\src\MyApp.2010\MyApp.Infrastructure.Repository.EF\Repository.EF\GenericRepository.cs:81 MyApp.Infrastructure.Repository.EF.GenericRepository1.get_ObjectSet() in C:\src\MyApp.2010\MyApp.Infrastructure.Repository.EF\Repository.EF\GenericRepository.cs:89 MyApp.Infrastructure.Repository.EF.GenericRepository`1.GetQuery() in C:\src\MyApp.2010\MyApp.Infrastructure.Repository.EF\Repository.EF\GenericRepository.cs:102


Solution

  • Without modifying either of them the answer is no because they both replace database provider but those replacements are not compatible.