My DbContext ctor looks like this:
public class FnordDbContext : DbContext
{
public FnordDbContext() : base("Fnord")
{
}
/* stuff */
}
And my mvc-mini-profiler bootstrapper looks like this:
var sqlConnectionFactory = new SqlConnectionFactory(ConfigurationManager.ConnectionStrings["Fnord"].ConnectionString);
var profiledConnectionFactory = new MvcMiniProfiler.Data.ProfiledDbConnectionFactory(sqlConnectionFactory);
Database.DefaultConnectionFactory = profiledConnectionFactory;
If I remove the connection string in my DbContext ctor, I get profiling as expected. But I don't want to have to name my connection string according to EF's convention. What do I need to change to make mvc-mini-profiler work with my DbContext use?
You can pass in the a ProfiledDbConnection explicitly to the ctor of your DbContext:
public class MyDbContext : DbContext {
public MyDbContext()
: base(GetProfiledConnection()) {
}
private static DbConnection GetProfiledConnection() {
var connectionString = ConfigurationManager.ConnectionStrings["name"].ConnectionString;
var connection = new SqlConnection(connectionString);
return ProfiledDbConnection.Get(connection);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With