2番目の'obj.Insert()'が例外をスローした場合に、すべての変更がロールバックされるように、複数のオブジェクトを保存するための最良の方法を知りたいです。
私はそのようなことを試みています:
Product product1 = new Product();
Product product2 = new Product();
Product product3 = new Product();
DbContext DB = new DB();
IProductInsert repository = new ProductInsert(DB);
repository.Insert(product1);
repository.Insert(product2);
repository.Insert(product3);
DB.SaveChanges();
しかし、それは私の見解では、正しくないと思います。
リポジトリクラスのDB.SaveChanges()を使用して、すべての変更またはロールバックを保存するにはどうすればよいですか?