英文:
SaveChangesOnDbContextAsync has never been called
问题
ABP已添加了一个可重写的函数,名为SaveChangesOnDbContextAsync
,允许我们拦截任何插入/更新/删除操作,具体信息请参见此链接:https://github.com/abpframework/abp/issues/4659
我尝试重写SaveChangesOnDbContextAsync
,在一个继承自AbpDbContext的类中,就像以下示例一样,但无论我何时更新数据,它都从未被调用:
public override async Task<int> SaveChangesOnDbContextAsync(bool acceptAllChangesOnSuccess, CancellationToken cancellationToken = default)
{
var result = await base.SaveChangesAsync();
return result;
}
英文:
ABP has added an overridable function called SaveChangesOnDbContextAsync
that allow us to intercept any insert/update/delete operation as in this link: https://github.com/abpframework/abp/issues/4659
I tried to override SaveChangesOnDbContextAsync in a class that inherits AbpDbContext like the following but it has never been called whenever I update the data:
public override async Task<int> SaveChangesOnDbContextAsync(bool acceptAllChangesOnSuccess, CancellationToken cancellationToken = default)
{
var result = await base.SaveChangesAsync();
return result;
}
答案1
得分: 0
这个方法是为了让你的应用程序代码绕过AbpDbContext.SaveChangesAsync()
中的逻辑而提供的。ABP不会调用它。
这是请求者的意思:
public override async Task<int> SaveChangesAsync(bool acceptAllChangesOnSuccess, CancellationToken cancellationToken = default)
{
try
{
return await base.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken);
}
catch (AbpDbConcurrencyException)
{
// 处理它
// ...
// 直接调用Microsoft.EntityFrameworkCore.DbContext的SaveChangesAsync(bool, CancellationToken),以避免反复创建审计日志、更新并发标记或触发实体事件等,就像AbpDbContext的版本所做的那样
return await base.SaveChangesOnDbContextAsync(acceptAllChangesOnSuccess, cancellationToken);
}
}
你可能只需要重写SaveChangesAsync
。
英文:
That method is provided for your application code to bypass the logic in AbpDbContext.SaveChangesAsync()
. ABP does not call it.
This is what the requestor meant:
public override async Task<int> SaveChangesAsync(bool acceptAllChangesOnSuccess, CancellationToken cancellationToken = default)
{
try
{
return await base.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken);
}
catch (AbpDbConcurrencyException)
{
// Handle it
// ...
// Directly call Microsoft.EntityFrameworkCore.DbContext's SaveChangesAsync(bool, CancellationToken) to not repeatedly
// create audit logs, update concurrencystamps, or trigger entity events etc. as AbpDbContext's version would do
return await base.SaveChangesOnDbContextAsync(acceptAllChangesOnSuccess, cancellationToken);
}
}
You probably just want to override SaveChangesAsync
instead.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论