这是配置文件:
internal sealed class Configuration : DbMigrationsConfiguration<Context>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
}
protected override void Seed(Context context)
{
//my seeding DB, here's an example
context.HomePageAreas
.AddOrUpdate(new HomePageArea { Title = HomePageArea.TopAreaKey });
}
}
应用启动:
Database.SetInitializer<Context>(
new MigrateDatabaseToLatestVersion<Context, Configuration>());
using (var context = new Context())
context.Database.Initialize(false);
然后我得到DbEntityValidationException
每个添加的行(从第二次启动开始):
{0}:已有一个“{1}”记录,其“{0}”字段设置为“{2}”。