问题
I am using CodeFirst approach in Entity Framework 6 and running my migration script manually to create Db and later update the changes in the schema.
I have noticed that every time the context is initialized, it checks for the "INFORMATION_SCHEMA.TABLES" and "MigrationHistory" metadata in the database. That adds 2 additional queries for each call.
This may not be a desirable situation for production environment. Is there a way to set it only once during application startup and these 2 process does not executed every time the DbContext is initialized.
Thanks
回答1:
Finally solved it the following way and wish to share the solution:
class MyCustomDbConfiguration : DbConfiguration
{
public MyCustomDbConfiguration()
{
SetDatabaseInitializer(new NullDatabaseInitializer<MyDbContext>());
}
}
来源:https://stackoverflow.com/questions/31220344/how-to-disable-migration-verification-during-every-dbcontext-initialization