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;

        }

}