1
下面是配置文件:播種時如何避免重複行?
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}」。
如果我想比較兩列,該怎麼辦? – Shimmy
嘗試使用'x => new {x.Prop1,x.Prop2}' –