From db94cd32d5a1fecf442dcd2ab7e64fb26308e1b7 Mon Sep 17 00:00:00 2001 From: Bi8bo <2738644273@qq.com> Date: Mon, 2 Sep 2024 15:01:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=95=E5=AE=9E=E4=BD=93=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E6=94=AF=E6=8C=81abp=20IHasConcurrencyStamp=E6=8E=A5=E5=8F=A3,?= =?UTF-8?q?=E4=B9=90=E8=A7=82=E9=94=81=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repositories/SqlSugarRepository.cs | 6 ++++++ .../Yi.Framework.SqlSugarCore/SqlSugarDbContext.cs | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) 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)) {