feat: 优化异步操作
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Nito.AsyncEx;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using Volo.Abp;
|
using Volo.Abp;
|
||||||
using Volo.Abp.Auditing;
|
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 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;
|
private ISugarDbContextProvider<ISqlSugarDbContext> _sugarDbContextProvider;
|
||||||
public IAsyncQueryableExecuter AsyncExecuter { get; }
|
public IAsyncQueryableExecuter AsyncExecuter { get; }
|
||||||
@@ -36,9 +37,7 @@ namespace Yi.Framework.SqlSugarCore.Repositories
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public virtual async Task<ISqlSugarClient> GetDbContextAsync()
|
public virtual async Task<ISqlSugarClient> GetDbContextAsync()
|
||||||
{
|
{
|
||||||
|
|
||||||
var db = (await _sugarDbContextProvider.GetDbContextAsync()).SqlSugarClient;
|
var db = (await _sugarDbContextProvider.GetDbContextAsync()).SqlSugarClient;
|
||||||
//await Console.Out.WriteLineAsync("获取的id:" + db.ContextID);
|
|
||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ namespace Yi.Framework.SqlSugarCore.Uow
|
|||||||
|
|
||||||
public ISqlSugarDbContext GetDbContext()
|
public ISqlSugarDbContext GetDbContext()
|
||||||
{
|
{
|
||||||
|
|
||||||
return _sqlsugarDbContext;
|
return _sqlsugarDbContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user