EF5.自动更新数据库结构,并且不丢失原数据

 Global.Application_Start()调用DB结构初始化

Database.SetInitializer<YourContex>(new YourInitializer());
    public class YourInitializer : DropCreateDatabaseIfModelChanges<YourContex>
    {
        protected override void Seed(YourContex context)
        {
             // This method will be called after migrating to the latest version.
            // You can use the DbSet<T>.AddOrUpdate() helper extension method
        }
    }
    internal sealed class Configuration : DbMigrationsConfiguration<YourContex>
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = true; 
            AutomaticMigrationDataLossAllowed = true;
        }
}
原文地址:https://www.cnblogs.com/baobao2010/p/2934682.html