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