时间:2021-07-01 10:21:17 帮助过:27人阅读
要使用上述DB初始化策略之一,必须在Context类中使用Database类设置DB初始值设定项,如下所示:
public class SchoolDBContext: DbContext { public SchoolDBContext(): base("SchoolDBConnectionString") { Database.SetInitializer<SchoolDBContext>(new CreateDatabaseIfNotExists<SchoolDBContext>()); //Database.SetInitializer<SchoolDBContext>(new DropCreateDatabaseIfModelChanges<SchoolDBContext>()); //Database.SetInitializer<SchoolDBContext>(new DropCreateDatabaseAlways<SchoolDBContext>()); //Database.SetInitializer<SchoolDBContext>(new SchoolDBInitializer()); } public DbSet<Student> Students { get; set; } public DbSet<Standard> Standards { get; set; } }
Code-First 数据库初始化策略
标签:cti asp ges 数据 www. str rds change 模式