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;
        }
}

 

posted @ 2013-02-27 10:24  陈跳跳  阅读(1800)  评论(0)    收藏  举报