I would like to know what's the best way to save multiple objects in a way that if the second 'obj.Insert()' throw a exception, all the changes rollback.
I a'm trying something like that:
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();
But it is in my view, I think it's not correct..
How can I save all the changes or rollback using the DB.SaveChanges() in my repository classes?