diff --git a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/Repositories/SqlSugarRepository.cs b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/Repositories/SqlSugarRepository.cs index 38cf18d3..537a5051 100644 --- a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/Repositories/SqlSugarRepository.cs +++ b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/Repositories/SqlSugarRepository.cs @@ -372,6 +372,12 @@ namespace Yi.Framework.SqlSugarCore.Repositories public virtual async Task UpdateAsync(TEntity updateObj) { + if (typeof(TEntity).IsAssignableTo())//带版本号乐观锁更新 + { + int num = await (await GetDbSimpleClientAsync()) + .Context.Updateable(updateObj).ExecuteCommandWithOptLockAsync(); + return num>0; + } return await (await GetDbSimpleClientAsync()).UpdateAsync(updateObj); } diff --git a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/SqlSugarDbContext.cs b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/SqlSugarDbContext.cs index 528ac602..7600dfb1 100644 --- a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/SqlSugarDbContext.cs +++ b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/SqlSugarDbContext.cs @@ -320,9 +320,11 @@ namespace Yi.Framework.SqlSugarCore /// 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)) {