Insertion order of multiple records in Entity Framework

后端 未结 6 1784
陌清茗
陌清茗 2020-12-11 01:49

I\'m having trouble with EF reordering my inserts when I try and add an entity with multiple children all at once. I\'ve got a 3 level structure with one-to-many relationsh

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-11 02:52

    I've found a way to do it. It just thought I'd let you know:

    using (var dbContextTransaction = dbContext.Database.BeginTransaction())
    {
      dbContext.SomeTables1.Add(object1);
      dbContext.SaveChanges();
    
      dbContext.SomeTables1.Add(object2);
      dbContext.SaveChanges();
    
      dbContextTransaction.Commit();
    }
    

提交回复
热议问题