如何禁用代码优先迁移 [英] How can I disable code first migrations

查看:28
本文介绍了如何禁用代码优先迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 EF5 中有一个代码优先实体模型.但我想手动管理数据库更改——我不希望 EF 修改我现有的数据库及其所有数据.但是当我在 EF 映射和数据库中进行并行更改时,EF 拒绝正确操作,告诉我我需要使用代码优先迁移.如何关闭此功能?

I have a code-first entity model in EF5. But I want to manage the database changes manually -- I do not want EF to modify my existing database and all its data. But when I make parallel changes in the EF mapping and in the database, EF refuses to operate properly telling me I need to use code first migration. How do I turn this off?

推荐答案

将 Database.SetInitializer 设置为 null.

set the Database.SetInitializer to null.

public class DatabaseContext: DbContext
{
    //the base accepts the name of the connection string provided in the web.config as a parameter
    public DatabaseContext()
        : base("DatabaseContext")
    {
        //disable initializer
        Database.SetInitializer<DatabaseContext>(null);
    }

这篇关于如何禁用代码优先迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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