From eb8d1626eaeaf6b45f0ddf8137420aa7708325e8 Mon Sep 17 00:00:00 2001 From: Bi8bo <2738644273@qq.com> Date: Mon, 2 Sep 2024 16:06:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B9=B6=E5=8F=91=E4=BF=AE=E6=94=B9=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E4=BF=AE=E6=94=B9=E4=B8=BA=E5=BC=82=E5=B8=B8=E6=8A=9B?= =?UTF-8?q?=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repositories/SqlSugarRepository.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 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 537a5051..50bad3c5 100644 --- a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/Repositories/SqlSugarRepository.cs +++ b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/Repositories/SqlSugarRepository.cs @@ -1,8 +1,11 @@ using System.Linq; using System.Linq.Expressions; +using System.Text; +using Microsoft.Extensions.Logging; using SqlSugar; using Volo.Abp; using Volo.Abp.Auditing; +using Volo.Abp.Data; using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Repositories; using Volo.Abp.Linq; @@ -374,9 +377,17 @@ namespace Yi.Framework.SqlSugarCore.Repositories { if (typeof(TEntity).IsAssignableTo())//带版本号乐观锁更新 { - int num = await (await GetDbSimpleClientAsync()) - .Context.Updateable(updateObj).ExecuteCommandWithOptLockAsync(); - return num>0; + try + { + int num = await (await GetDbSimpleClientAsync()) + .Context.Updateable(updateObj).ExecuteCommandWithOptLockAsync(true); + return num>0; + } + catch (VersionExceptions ex) + { + + throw new AbpDbConcurrencyException($"{ex.Message}[更新失败:ConcurrencyStamp不是最新版本],entityInfo:{updateObj}", ex); + } } return await (await GetDbSimpleClientAsync()).UpdateAsync(updateObj); }