What is the best way to delete a collection and then insert a replacement collection in a single transaction?
For example, I've made some changes to a User's UserGroup collection and now I want to replace the existing collection in the database with the new one so:
UnitOfWork uow = new UnitOfWork();
uow.AddCollectionForDelete(new UserEntity(user.UserId).UserGroup);
uow.AddCollectionForSave(user.UserGroup);
uow.Commit(new Transaction(IsolationLevel.ReadCommitted, "ReplaceUserGroups"), true);
But after the commit I lose any existing UserGroups from the database, presumably because the delete is happening after the insert in the UnitOfWork.
What is the correct approach here?
Thanks, J.S.