当前位置:网站首页>EF data migration

EF data migration

2022-07-24 16:30:00 Weiwei became a father

1. Tools ->NuGet Package manager -> Package manager console input enable-migrations( Open data migration )

            There will be one more after the implementation 'Migrations' Folder , There will be 'Configuration.cs' The contents of the file settings are as follows :

        public Configuration()
        {
            AutomaticMigrationsEnabled = true;// Indicates whether automatic migration values can be used when migrating databases 
            AutomaticMigrationDataLossAllowed = true;// Whether to accept the value of data loss during automatic migration 
        }

2. stay CodeFrist Add a statement to the constructor in the context of

        public Context()
            : base("name=Context")
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<Context, Migrations.Configuration>("Context"));    // Add this statement 
        }

 

Then move to other places ( It cannot be modified without migration ) You can update and modify the fields inside , Delete , After generation, the database will change

原网站

版权声明
本文为[Weiwei became a father]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/203/202207211501207807.html