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 647ca0e8..65c83f13 100644
--- a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore.Abstractions/DbConnOptions.cs
+++ b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore.Abstractions/DbConnOptions.cs
@@ -60,8 +60,8 @@ namespace Yi.Framework.SqlSugarCore.Abstractions
public bool EnabledSaasMultiTenancy { get; set; } = false;
///
- /// 并发乐观锁异常,否则不处理
+ /// 是否开启更新并发乐观锁
///
- public bool EnabledConcurrencyException { get; set; } = true;
+ 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 1cc1ea61..786254ec 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,7 @@
-using System.Linq;
using System.Linq.Expressions;
-using System.Text;
-using Microsoft.Extensions.Logging;
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;
@@ -17,18 +12,17 @@ using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.SqlSugarCore.Repositories
{
- public class SqlSugarRepository : ISqlSugarRepository, IRepository
- where TEntity : class, IEntity, new()
+ public class SqlSugarRepository : ISqlSugarRepository, IRepository where TEntity : class, IEntity, new()
{
public ISqlSugarClient _Db => AsyncContext.Run(async () => await GetDbContextAsync());
public ISugarQueryable _DbQueryable => _Db.Queryable();
private readonly ISugarDbContextProvider _dbContextProvider;
-
+
public IAbpLazyServiceProvider LazyServiceProvider { get; set; }
+
protected DbConnOptions? Options => LazyServiceProvider?.LazyGetService>().Value;
-
///
/// 异步查询执行器
///
@@ -64,26 +58,22 @@ namespace Yi.Framework.SqlSugarCore.Repositories
#region Abp模块
- public virtual async Task FindAsync(Expression> predicate,
- bool includeDetails = true, CancellationToken cancellationToken = default)
+ public virtual async Task FindAsync(Expression> predicate, bool includeDetails = true, CancellationToken cancellationToken = default)
{
return await GetFirstAsync(predicate);
}
- public virtual async Task GetAsync(Expression> predicate,
- bool includeDetails = true, CancellationToken cancellationToken = default)
+ public virtual async Task GetAsync(Expression> predicate, bool includeDetails = true, CancellationToken cancellationToken = default)
{
return await GetFirstAsync(predicate);
}
- public virtual async Task DeleteAsync(Expression> predicate, bool autoSave = false,
- CancellationToken cancellationToken = default)
+ public virtual async Task DeleteAsync(Expression> predicate, bool autoSave = false, CancellationToken cancellationToken = default)
{
await this.DeleteAsync(predicate);
}
- public virtual async Task DeleteDirectAsync(Expression> predicate,
- CancellationToken cancellationToken = default)
+ public virtual async Task DeleteDirectAsync(Expression> predicate, CancellationToken cancellationToken = default)
{
await this.DeleteAsync(predicate);
}
@@ -113,71 +103,60 @@ namespace Yi.Framework.SqlSugarCore.Repositories
throw new NotImplementedException();
}
- public virtual async Task> GetListAsync(Expression> predicate,
- bool includeDetails = false, CancellationToken cancellationToken = default)
+ public virtual async Task> GetListAsync(Expression> predicate, bool includeDetails = false, CancellationToken cancellationToken = default)
{
return await GetListAsync(predicate);
}
- public virtual async Task InsertAsync(TEntity entity, bool autoSave = false,
- CancellationToken cancellationToken = default)
+ public virtual async Task InsertAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default)
{
return await InsertReturnEntityAsync(entity);
}
- public virtual async Task InsertManyAsync(IEnumerable entities, bool autoSave = false,
- CancellationToken cancellationToken = default)
+ public virtual async Task InsertManyAsync(IEnumerable entities, bool autoSave = false, CancellationToken cancellationToken = default)
{
await InsertRangeAsync(entities.ToList());
}
- public virtual async Task UpdateAsync(TEntity entity, bool autoSave = false,
- CancellationToken cancellationToken = default)
+ public virtual async Task UpdateAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default)
{
await UpdateAsync(entity);
return entity;
}
- public virtual async Task UpdateManyAsync(IEnumerable entities, bool autoSave = false,
- CancellationToken cancellationToken = default)
+ public virtual async Task UpdateManyAsync(IEnumerable entities, bool autoSave = false, CancellationToken cancellationToken = default)
{
await UpdateRangeAsync(entities.ToList());
}
- public virtual async Task DeleteAsync(TEntity entity, bool autoSave = false,
- CancellationToken cancellationToken = default)
+ public virtual async Task DeleteAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default)
{
await DeleteAsync(entity);
}
- public virtual async Task DeleteManyAsync(IEnumerable entities, bool autoSave = false,
- CancellationToken cancellationToken = default)
+ public virtual async Task DeleteManyAsync(IEnumerable entities, bool autoSave = false, CancellationToken cancellationToken = default)
{
await DeleteAsync(entities.ToList());
}
- public virtual async Task> GetListAsync(bool includeDetails = false,
- CancellationToken cancellationToken = default)
+ public virtual async Task> GetListAsync(bool includeDetails = false, CancellationToken cancellationToken = default)
{
return await GetListAsync();
}
public virtual async Task GetCountAsync(CancellationToken cancellationToken = default)
{
- return await this.CountAsync(_ => true);
+ return await this.CountAsync(_=>true);
}
- public virtual async Task> GetPagedListAsync(int skipCount, int maxResultCount, string sorting,
- bool includeDetails = false, CancellationToken cancellationToken = default)
+ public virtual async Task> GetPagedListAsync(int skipCount, int maxResultCount, string sorting, bool includeDetails = false, CancellationToken cancellationToken = default)
{
return await GetPageListAsync(_ => true, skipCount, maxResultCount);
}
-
#endregion
#region 内置DB快捷操作
-
public virtual async Task> AsDeleteable()
{
return (await GetDbSimpleClientAsync()).AsDeleteable();
@@ -192,7 +171,7 @@ namespace Yi.Framework.SqlSugarCore.Repositories
{
return (await GetDbSimpleClientAsync()).AsInsertable(insertObj);
}
-
+
public virtual async Task> AsInsertable(TEntity[] insertObjs)
{
return (await GetDbSimpleClientAsync()).AsInsertable(insertObjs);
@@ -232,11 +211,9 @@ namespace Yi.Framework.SqlSugarCore.Repositories
{
return (await GetDbSimpleClientAsync()).AsUpdateable(updateObjs);
}
-
#endregion
#region SimpleClient模块
-
public virtual async Task CountAsync(Expression> whereExpression)
{
return await (await GetDbSimpleClientAsync()).CountAsync(whereExpression);
@@ -253,6 +230,7 @@ namespace Yi.Framework.SqlSugarCore.Repositories
{
return await (await GetDbSimpleClientAsync()).DeleteAsync(deleteObj);
}
+
}
public virtual async Task DeleteAsync(List deleteObjs)
@@ -272,13 +250,13 @@ namespace Yi.Framework.SqlSugarCore.Repositories
{
if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity)))
{
- return await (await GetDbSimpleClientAsync()).AsUpdateable()
- .SetColumns(nameof(ISoftDelete.IsDeleted), true).Where(whereExpression).ExecuteCommandAsync() > 0;
+ return await (await GetDbSimpleClientAsync()).AsUpdateable().SetColumns(nameof(ISoftDelete.IsDeleted), true).Where(whereExpression).ExecuteCommandAsync() > 0;
}
else
{
return await (await GetDbSimpleClientAsync()).DeleteAsync(whereExpression);
}
+
}
public virtual async Task DeleteByIdAsync(dynamic id)
@@ -286,11 +264,7 @@ namespace Yi.Framework.SqlSugarCore.Repositories
if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity)))
{
var entity = await GetByIdAsync(id);
- if (entity is null)
- {
- return false;
- }
-
+ if (entity == null) return false;
//反射赋值
ReflexHelper.SetModelValue(nameof(ISoftDelete.IsDeleted), true, entity);
return await UpdateAsync(entity);
@@ -311,7 +285,6 @@ namespace Yi.Framework.SqlSugarCore.Repositories
{
return false;
}
-
//反射赋值
entities.ForEach(e => ReflexHelper.SetModelValue(nameof(ISoftDelete.IsDeleted), true, e));
return await UpdateRangeAsync(entities);
@@ -320,6 +293,7 @@ namespace Yi.Framework.SqlSugarCore.Repositories
{
return await (await GetDbSimpleClientAsync()).DeleteByIdAsync(ids);
}
+
}
public virtual async Task GetByIdAsync(dynamic id)
@@ -328,6 +302,7 @@ namespace Yi.Framework.SqlSugarCore.Repositories
}
+
public virtual async Task GetFirstAsync(Expression> whereExpression)
{
return await (await GetDbSimpleClientAsync()).GetFirstAsync(whereExpression);
@@ -343,19 +318,14 @@ namespace Yi.Framework.SqlSugarCore.Repositories
return await (await GetDbSimpleClientAsync()).GetListAsync(whereExpression);
}
- public virtual async Task> GetPageListAsync(Expression> whereExpression,
- int pageNum, int pageSize)
+ public virtual async Task> GetPageListAsync(Expression> whereExpression, int pageNum, int pageSize)
{
- return await (await GetDbSimpleClientAsync()).GetPageListAsync(whereExpression,
- new PageModel() { PageIndex = pageNum, PageSize = pageSize });
+ return await (await GetDbSimpleClientAsync()).GetPageListAsync(whereExpression, new PageModel() { PageIndex = pageNum, PageSize = pageSize });
}
- public virtual async Task> GetPageListAsync(Expression> whereExpression,
- int pageNum, int pageSize, Expression>? orderByExpression = null,
- OrderByType orderByType = OrderByType.Asc)
+ public virtual async Task> GetPageListAsync(Expression> whereExpression, int pageNum, int pageSize, Expression>? orderByExpression = null, OrderByType orderByType = OrderByType.Asc)
{
- return await (await GetDbSimpleClientAsync()).GetPageListAsync(whereExpression,
- new PageModel { PageIndex = pageNum, PageSize = pageSize }, orderByExpression, orderByType);
+ return await (await GetDbSimpleClientAsync()).GetPageListAsync(whereExpression, new PageModel { PageIndex = pageNum, PageSize = pageSize }, orderByExpression, orderByType);
}
public virtual async Task GetSingleAsync(Expression> whereExpression)
@@ -410,9 +380,9 @@ namespace Yi.Framework.SqlSugarCore.Repositories
public virtual async Task UpdateAsync(TEntity updateObj)
{
- if (typeof(TEntity).IsAssignableTo()) //带版本号乐观锁更新
+ if (Options is not null && Options.EnabledConcurrencyException)
{
- if (Options is not null && Options.EnabledConcurrencyException)
+ if (typeof(TEntity).IsAssignableTo()) //带版本号乐观锁更新
{
try
{
@@ -426,24 +396,18 @@ namespace Yi.Framework.SqlSugarCore.Repositories
$"{ex.Message}[更新失败:ConcurrencyStamp不是最新版本],entityInfo:{updateObj}", ex);
}
}
- else
- {
- int num = await (await GetDbSimpleClientAsync())
- .Context.Updateable(updateObj).ExecuteCommandAsync();
- return num > 0;
- }
}
return await (await GetDbSimpleClientAsync()).UpdateAsync(updateObj);
}
- public virtual async Task UpdateAsync(Expression> columns,
- Expression> whereExpression)
+ public virtual async Task UpdateAsync(Expression> columns, Expression> whereExpression)
{
return await (await GetDbSimpleClientAsync()).UpdateAsync(columns, whereExpression);
}
+
public virtual async Task UpdateRangeAsync(List updateObjs)
{
return await (await GetDbSimpleClientAsync()).UpdateRangeAsync(updateObjs);
@@ -452,36 +416,30 @@ namespace Yi.Framework.SqlSugarCore.Repositories
#endregion
}
- public class SqlSugarRepository : SqlSugarRepository, ISqlSugarRepository,
- IRepository where TEntity : class, IEntity, new()
+ public class SqlSugarRepository : SqlSugarRepository, ISqlSugarRepository, IRepository where TEntity : class, IEntity, new()
{
- public SqlSugarRepository(ISugarDbContextProvider dbContextProvider) : base(
- dbContextProvider)
+ public SqlSugarRepository(ISugarDbContextProvider sugarDbContextProvider) : base(sugarDbContextProvider)
{
}
- public virtual async Task DeleteAsync(TKey id, bool autoSave = false,
- CancellationToken cancellationToken = default)
+ public virtual async Task DeleteAsync(TKey id, bool autoSave = false, CancellationToken cancellationToken = default)
{
await DeleteByIdAsync(id);
}
- public virtual async Task DeleteManyAsync(IEnumerable ids, bool autoSave = false,
- CancellationToken cancellationToken = default)
+ public virtual async Task DeleteManyAsync(IEnumerable ids, bool autoSave = false, CancellationToken cancellationToken = default)
{
await DeleteByIdsAsync(ids.Select(x => (object)x).ToArray());
}
- public virtual async Task FindAsync(TKey id, bool includeDetails = true,
- CancellationToken cancellationToken = default)
+ public virtual async Task FindAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default)
{
return await GetByIdAsync(id);
}
- public virtual async Task GetAsync(TKey id, bool includeDetails = true,
- CancellationToken cancellationToken = default)
+ public virtual async Task GetAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default)
{
return await GetByIdAsync(id);
}
}
-}
\ No newline at end of file
+}
diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain.Shared/Caches/FileCacheItem.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain.Shared/Caches/FileCacheItem.cs
index 47a91d4f..a8bfe3ab 100644
--- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain.Shared/Caches/FileCacheItem.cs
+++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain.Shared/Caches/FileCacheItem.cs
@@ -1,4 +1,4 @@
-namespace Yi.Framework.Rbac.Domain.Shared.Caches;
+namespace Yi.Framework.Rbac.Domain.Shared.Caches;
public class FileCacheItem
{