I would vote for Stefan Moser, if I could, I would deal with Nh anyway, but I think it would be nice to write this code:
private void SaveForm()
{
using (var unitofwork = UnitOfWork.Start())
{
var foo = FooRepository.Get(_editingFooId);
var bar = BarRepository.Get(_barId);
foo.Name = txtName.Text;
bar.SomeOtherProperty = txtBlah.Text;
FooRepository.Save(foo);
BarRepository.Save(bar);
UnitOfWork.CommitChanges();
}
}
Thus, either the whole action succeeds, or it fails and rolls back, while retaining flushing / transaction control outside the repositories.
source
share