单实体更新支持abp IHasConcurrencyStamp接口,乐观锁更新

This commit is contained in:
Bi8bo
2024-09-02 15:01:49 +08:00
parent 67c7ef37e6
commit db94cd32d5
2 changed files with 10 additions and 2 deletions

View File

@@ -372,6 +372,12 @@ namespace Yi.Framework.SqlSugarCore.Repositories
public virtual async Task<bool> UpdateAsync(TEntity updateObj) public virtual async Task<bool> UpdateAsync(TEntity updateObj)
{ {
if (typeof(TEntity).IsAssignableTo<IHasConcurrencyStamp>())//带版本号乐观锁更新
{
int num = await (await GetDbSimpleClientAsync())
.Context.Updateable(updateObj).ExecuteCommandWithOptLockAsync();
return num>0;
}
return await (await GetDbSimpleClientAsync()).UpdateAsync(updateObj); return await (await GetDbSimpleClientAsync()).UpdateAsync(updateObj);
} }

View File

@@ -320,9 +320,11 @@ namespace Yi.Framework.SqlSugarCore
/// <param name="column"></param> /// <param name="column"></param>
protected virtual void EntityService(PropertyInfo property, EntityColumnInfo column) protected virtual void EntityService(PropertyInfo property, EntityColumnInfo column)
{ {
if (property.Name == "ConcurrencyStamp") if (property.Name == nameof(IHasConcurrencyStamp.ConcurrencyStamp)) //带版本号并发更新
{ {
column.IsIgnore = true; // column.IsOnlyIgnoreInsert = true;
// column.IsOnlyIgnoreUpdate = true;
column.IsEnableUpdateVersionValidation = true;
} }
if (property.PropertyType == typeof(ExtraPropertyDictionary)) if (property.PropertyType == typeof(ExtraPropertyDictionary))
{ {