5 つ以上のテーブルに連続してレコードを追加しようとしているというシナリオがあります。保存メカニズムは厳密である必要があり、すべてのオブジェクトが失敗すると、すべてのデータベースの変更がコミットまたはロールバックされません。すべてのオブジェクトが問題なく挿入された場合は、すべてのレコードをデータベースに保存する必要があります。以下は私のサンプルコードです。助けてください。
_dbContext.Table1.AddObject(object1);//if insert fails rollback
_dbContext.SaveChanges();
_dbContext.Table2.AddObject(object2);//if insert fails rollback this and object1 transactions
_dbContext.SaveChanges();
_dbContext.Table3.AddObject(object3);//if insert fails rollback this and previous other transactions
_dbContext.SaveChanges();
_dbContext.Table4.AddObject(object4);//if insert fails rollback this and previous other transactions
_dbContext.SaveChanges();
_dbContext.Table5.AddObject(object5);//if insert fails rollback this and previous other transactions
_dbContext.SaveChanges();
//if all objects were inserted without exceptions then commit all changes