diff --git a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore.Abstractions/DbConnOptions.cs b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore.Abstractions/DbConnOptions.cs
index 6f48f14d..65c83f13 100644
--- a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore.Abstractions/DbConnOptions.cs
+++ b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore.Abstractions/DbConnOptions.cs
@@ -58,5 +58,10 @@ namespace Yi.Framework.SqlSugarCore.Abstractions
/// 是否启用SaaS多租户
///
public bool EnabledSaasMultiTenancy { get; set; } = false;
+
+ ///
+ /// 是否开启更新并发乐观锁
+ ///
+ public bool EnabledConcurrencyException { get;set; } = false;
}
}
\ No newline at end of file
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 9243e5ed..4b3b7023 100644
--- a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/Repositories/SqlSugarRepository.cs
+++ b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/Repositories/SqlSugarRepository.cs
@@ -1,12 +1,9 @@
-using System.Linq;
-using System.Linq.Expressions;
-using System.Text;
-using Microsoft.Extensions.Logging;
+using System.Linq.Expressions;
+using Microsoft.Extensions.Options;
using Nito.AsyncEx;
using SqlSugar;
-using Volo.Abp;
-using Volo.Abp.Auditing;
using Volo.Abp.Data;
+using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Linq;
@@ -23,6 +20,9 @@ namespace Yi.Framework.SqlSugarCore.Repositories
private readonly ISugarDbContextProvider _dbContextProvider;
+ public IAbpLazyServiceProvider LazyServiceProvider { get; set; }
+
+ protected DbConnOptions? Options => LazyServiceProvider?.LazyGetService>().Value;
///
/// 异步查询执行器
///
@@ -380,20 +380,24 @@ namespace Yi.Framework.SqlSugarCore.Repositories
public virtual async Task UpdateAsync(TEntity updateObj)
{
- if (typeof(TEntity).IsAssignableTo())//带版本号乐观锁更新
+ if (Options is not null && Options.EnabledConcurrencyException)
{
- try
+ if (typeof(TEntity).IsAssignableTo()) //带版本号乐观锁更新
{
- 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);
+ 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);
}
diff --git a/Yi.Abp.Net8/src/Yi.Abp.Web/appsettings.json b/Yi.Abp.Net8/src/Yi.Abp.Web/appsettings.json
index 1b1eee0e..ba5ec320 100644
--- a/Yi.Abp.Net8/src/Yi.Abp.Web/appsettings.json
+++ b/Yi.Abp.Net8/src/Yi.Abp.Web/appsettings.json
@@ -40,7 +40,8 @@
"EnabledDbSeed": true,
"EnableUnderLine": false, // 启用驼峰转下划线
//SAAS多租户
- "EnabledSaasMultiTenancy": true
+ "EnabledSaasMultiTenancy": true,
+ "EnabledConcurrencyException": false
//读写分离地址
//"ReadUrl": [
// "DataSource=[xxxx]", //Sqlite