Handling errors on IUnitOfWork.Commit

Sep 19, 2013 at 5:49 PM
How suppose to be handled errors on saving entities through your library. I can't find any examples. Or threads about that.
As for my understanding Repositories should only modified state of entities or query them from data base if there are not yet available from cache. For saving changes should be used Commit from IUnitOfWork. Sadly there is not any method in this interface for rollback of changes in case saving of them fails. If repositories are reused between methods (like in my case), first error will throw them of balance and leave in unpredictable state.

For example:
public class Model
{
   IRepository<Person> repository;
   public Model(IRepository<Person> repository)
   {
       this.repository = repository;
   }
   public SavePerson(Person newPerson)
   {
       using(var uow = UOWFactory.Get())
       {
           repository.Insert(newPerson);
           //this will fail because newPerson don't have Name and Name is NOT NULL in DB
           uow.Commit()
           //from now on any subsequent calls to DBContext.SaveChanges fails, because
           //repository instance locks DBContext changed entities collection
       }
   }
}