How to disable Migration Verification during every DbContext initialization

我是研究僧i 提交于 2019-12-24 09:06:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!