How can I disable code first migrations

后端 未结 5 1653
醉话见心
醉话见心 2020-11-30 23:05

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 m

5条回答
  •  北荒
    北荒 (楼主)
    2020-11-30 23:20

    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(null);
        }
    

提交回复
热议问题