删除前无法更新记录
Unable to update record prior to deletion
在我的一项应用程序服务中,我试图在删除之前更新记录(使用软删除)。
玩了之后,我发现我可以更新记录或删除它,但我不能两者都做。最后一个操作(在本例中为删除)始终优先。
如果我删除然后更新,记录不会被标记为已删除并且列会更新,那么我如何在删除之前更新记录 url
和 displayname
?我添加了 UnitOfWork
属性,但它似乎没有任何影响
我的方法可以在下面找到。
[AbpAuthorize(AppPermissions.Pages_PmnyDocuments_Delete)]
[UnitOfWork]
public async Task Delete(EntityDto input)
{
var entity = await _pmnyDocumentsRepository.GetAsync(input.Id);
var output = await _fileServerManager.DeleteAsync(new DeleteFileServerObjectInput(PmnyConsts.Bucket, $"{entity.MasterId}/{entity.ParentIdentifier}".AsFilePath(), entity.DisplayName));
entity.Url = output.FilePath;
entity.DisplayName = output.FileName;
await _pmnyDocumentsRepository.UpdateAsync(entity);
var entity2 = await _pmnyDocumentsRepository.GetAsync(entity.Id);
await _pmnyDocumentsRepository.DeleteAsync(entity2.Id);
}
我会尝试删除 [UnitOfWork]
属性,而不是将更新和删除包装在他们自己的 uow 中。
using (var unitOfWork = _unitOfWorkManager.Begin())
{
//UPDATE
}
using (var unitOfWork = _unitOfWorkManager.Begin())
{
//DELETE
}
文档中有更多信息here
您需要在两次调用之间发出保存更改,因为所有对数据库的提交都会在您的方法结束时自动发生。
查看此引用
SaveChanges
ASP.NET Boilerplate saves all changes at the end of a unit of work. You don't have to do anything, but sometimes you may want to save changes to the database in the middle of a unit of work operation. For example, after saving some changes, we may want to get the Id of a newly inserted Entity using EntityFramework.
You can use the SaveChanges or SaveChangesAsync method of the current
unit of work.
Note that if the current unit of work is transactional, all changes in
the transaction are rolled back if an exception occurs. Even the saved
changes!
在我的一项应用程序服务中,我试图在删除之前更新记录(使用软删除)。 玩了之后,我发现我可以更新记录或删除它,但我不能两者都做。最后一个操作(在本例中为删除)始终优先。
如果我删除然后更新,记录不会被标记为已删除并且列会更新,那么我如何在删除之前更新记录 url
和 displayname
?我添加了 UnitOfWork
属性,但它似乎没有任何影响
我的方法可以在下面找到。
[AbpAuthorize(AppPermissions.Pages_PmnyDocuments_Delete)]
[UnitOfWork]
public async Task Delete(EntityDto input)
{
var entity = await _pmnyDocumentsRepository.GetAsync(input.Id);
var output = await _fileServerManager.DeleteAsync(new DeleteFileServerObjectInput(PmnyConsts.Bucket, $"{entity.MasterId}/{entity.ParentIdentifier}".AsFilePath(), entity.DisplayName));
entity.Url = output.FilePath;
entity.DisplayName = output.FileName;
await _pmnyDocumentsRepository.UpdateAsync(entity);
var entity2 = await _pmnyDocumentsRepository.GetAsync(entity.Id);
await _pmnyDocumentsRepository.DeleteAsync(entity2.Id);
}
我会尝试删除 [UnitOfWork]
属性,而不是将更新和删除包装在他们自己的 uow 中。
using (var unitOfWork = _unitOfWorkManager.Begin())
{
//UPDATE
}
using (var unitOfWork = _unitOfWorkManager.Begin())
{
//DELETE
}
文档中有更多信息here
您需要在两次调用之间发出保存更改,因为所有对数据库的提交都会在您的方法结束时自动发生。
查看此引用
SaveChanges ASP.NET Boilerplate saves all changes at the end of a unit of work. You don't have to do anything, but sometimes you may want to save changes to the database in the middle of a unit of work operation. For example, after saving some changes, we may want to get the Id of a newly inserted Entity using EntityFramework.
You can use the SaveChanges or SaveChangesAsync method of the current unit of work.
Note that if the current unit of work is transactional, all changes in the transaction are rolled back if an exception occurs. Even the saved changes!