public class DbHelper:DbContext
{
public DbHelper()
: base("strConn")
{
//自动创建表,如果Entity有改到就更新到表结构
Database.SetInitializer<DbHelper>(new MigrateDatabaseToLatestVersion<DbHelper, ReportingDbMigrationsConfiguration>());
}
public DbSet<Students> Students { get; set; }
}
internal sealed class ReportingDbMigrationsConfiguration : DbMigrationsConfiguration<DbHelper>
{
public ReportingDbMigrationsConfiguration()
{
AutomaticMigrationsEnabled = true;//任何Model Class的修改將會直接更新DB
AutomaticMigrationDataLossAllowed = true;
}
}