在aspnetboilerplate上工作,在app-service中具有以下类型的代码,如果发生错误,则删除后如果不执行已经从数据库中删除的unitOfWork.Complete()数据,则无法正常工作工作单元。
using (var unitOfWork = _unitOfWorkManager.Begin())
{
//delete all items in db....
var response = _grouppermissionRepository.HardDelete(p => p.GroupId == groupId);
foreach (var item in pageGroupPermissions)
{
if (item.IsChecked == true)
{
var grouppermissionObj = new Entities.Setup.GroupPermission()
{
CompanyId = null,
GroupId = item.GroupId,
IsActive = true,
IsDefault = true,
IsDeleted = false,
PageId = item.PageId,
Permission = item.Permission,
TenantId = 2
};
groupPermissions.Add(grouppermissionObj);
}
}
_grouppermissionRepository.GetDbContext().AddRange(groupPermissions);
unitOfWork.Complete();
}