如何在每次DbContext初始化期间禁用迁移验证 [英] How to disable Migration Verification during every DbContext initialization

查看:58
本文介绍了如何在每次DbContext初始化期间禁用迁移验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Entity Framework 6中使用CodeFirst方法,并手动运行迁移脚本来创建Db,然后在架构中更新更改.

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.

我注意到,每次上下文初始化时,都会在其中检查" INFORMATION_SCHEMA.TABLES "和" MigrationHistory "元数据数据库. 这将为每个呼叫添加2个其他查询 .

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.

对于生产环境,这可能不是理想的情况.有没有一种方法可以在应用程序启动期间将其设置一次,并且这2个过程不会在每次初始化DbContext时执行.

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.

谢谢

推荐答案

最后通过以下方式解决了该问题,并希望与您分享解决方案:

Finally solved it the following way and wish to share the solution:

class MyCustomDbConfiguration : DbConfiguration
        {
        public MyCustomDbConfiguration()
            {
            SetDatabaseInitializer(new NullDatabaseInitializer<MyDbContext>());
            }
        }

这篇关于如何在每次DbContext初始化期间禁用迁移验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆