feat: 优化异步操作

This commit is contained in:
橙子
2024-09-30 22:34:12 +08:00
parent 707e241f25
commit d4e8ce9c89
2 changed files with 3 additions and 5 deletions

View File

@@ -2,6 +2,7 @@
using System.Linq.Expressions;
using System.Text;
using Microsoft.Extensions.Logging;
using Nito.AsyncEx;
using SqlSugar;
using Volo.Abp;
using Volo.Abp.Auditing;
@@ -16,9 +17,9 @@ namespace Yi.Framework.SqlSugarCore.Repositories
{
public class SqlSugarRepository<TEntity> : ISqlSugarRepository<TEntity>, IRepository<TEntity> where TEntity : class, IEntity, new()
{
public ISqlSugarClient _Db => GetDbContextAsync().Result;
public ISqlSugarClient _Db => AsyncContext.Run(async () => await GetDbContextAsync());
public ISugarQueryable<TEntity> _DbQueryable => GetDbContextAsync().ConfigureAwait(false).GetAwaiter().GetResult().Queryable<TEntity>();
public ISugarQueryable<TEntity> _DbQueryable => _Db.Queryable<TEntity>();
private ISugarDbContextProvider<ISqlSugarDbContext> _sugarDbContextProvider;
public IAsyncQueryableExecuter AsyncExecuter { get; }
@@ -36,9 +37,7 @@ namespace Yi.Framework.SqlSugarCore.Repositories
/// <returns></returns>
public virtual async Task<ISqlSugarClient> GetDbContextAsync()
{
var db = (await _sugarDbContextProvider.GetDbContextAsync()).SqlSugarClient;
//await Console.Out.WriteLineAsync("获取的id" + db.ContextID);
return db;
}

View File

@@ -14,7 +14,6 @@ namespace Yi.Framework.SqlSugarCore.Uow
public ISqlSugarDbContext GetDbContext()
{
return _sqlsugarDbContext;
}