Closed RudeySH closed 6 years ago
I figured out how to make it work. Just wrap existing query providers in a new ProfiledQueryProvider
class with the following CanHandle
implementation:
public class ProfiledQueryProvider : IQueryProvider
{
private readonly IQueryProvider _provider;
public ProfiledQueryProvider(IQueryProvider queryProvider)
{
_provider = queryProvider;
}
public bool CanHandle(DbConnection storeConnection)
{
return _provider.CanHandle((storeConnection as ProfiledDbConnection)?.WrappedConnection ?? storeConnection);
}
// Implement other members of IQueryProvider, pass everything to _provider
}
Run this on startup, if you're adding custom query providers you should run this afterwards:
var providers = new IQueryProvider[EntityFramework.Utilities.Configuration.Providers.Count];
EntityFramework.Utilities.Configuration.Providers.CopyTo(providers, 0);
EntityFramework.Utilities.Configuration.Providers.Clear();
for (var i = 0; i < providers.Length; i++)
{
EntityFramework.Utilities.Configuration.Providers.Add(new ProfiledQueryProvider(providers[i]));
}
MiniProfiler wraps the connection to profile it, and now EFUtilities isn't able to recognize the underlying provider.
I'm not sure how EFUtilities detects the datasource. The error message above occurs when
DisableDefaultFallback
is true, but as far as I understand the source code this boolean is always true. I must be missing something here...