I enabled the migration, and I code the seed codes like follow:
protected override void Seed(DbContext c)
{
c.DbSet<Table1>.AddOrUpdate(..);
c.DbSet<Table2>.AddOrUpdate(..);
c.DbSet<Table3>.AddOrUpdate(..);
}
I need the table1 run in order, because the table2 references table1, and the table3 references table1 and table2.
but the EF6 has optimized the code generated T-SQL batchs, they query the table1 for table3's references, and there is nothing due to table1 hasn't initialized yet, and EF6 throw a exception.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…