【发布时间】:2012-12-03 15:25:19
【问题描述】:
这是配置文件:
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}”。
【问题讨论】:
标签: .net entity-framework ef-code-first entity-framework-migrations