mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
Update Core
This commit is contained in:
parent
f802407db4
commit
583ad3279e
@ -197,9 +197,8 @@ namespace OrmTest
|
||||
|
||||
SqlSugarClient db = GetInstance();
|
||||
var task1 = db.Queryable<Order>().FirstAsync();
|
||||
var task2 = db.Queryable<Order>().Where(it => it.Id == 1).ToListAsync();
|
||||
|
||||
task1.Wait();
|
||||
var task2 = db.Queryable<Order>().Where(it => it.Id == 1).ToListAsync();
|
||||
task2.Wait();
|
||||
|
||||
Console.WriteLine("#### Async End ####");
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,8 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public partial class DbBindAccessory
|
||||
@ -32,6 +35,31 @@ namespace SqlSugar
|
||||
}
|
||||
return result;
|
||||
}
|
||||
protected async Task<List<T>> GetEntityListAsync<T>(SqlSugarProvider context, IDataReader dataReader)
|
||||
{
|
||||
Type type = typeof(T);
|
||||
var fieldNames = GetDataReaderNames(dataReader);
|
||||
string cacheKey = GetCacheKey(type, fieldNames);
|
||||
IDataReaderEntityBuilder<T> entytyList = context.Utilities.GetReflectionInoCacheInstance().GetOrCreate(cacheKey, () =>
|
||||
{
|
||||
var cacheResult = new IDataReaderEntityBuilder<T>(context, dataReader, fieldNames).CreateBuilder(type);
|
||||
return cacheResult;
|
||||
});
|
||||
List<T> result = new List<T>();
|
||||
try
|
||||
{
|
||||
if (dataReader == null) return result;
|
||||
while (await((DbDataReader)dataReader).ReadAsync())
|
||||
{
|
||||
result.Add(entytyList.Build(dataReader));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Check.Exception(true, ErrorMessage.EntityMappingError, ex.Message);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private string GetCacheKey(Type type,List<string> keys)
|
||||
{
|
||||
@ -60,6 +88,23 @@ namespace SqlSugar
|
||||
{
|
||||
List<T> result = new List<T>();
|
||||
while (dataReader.Read())
|
||||
{
|
||||
GetKeyValueList(type, dataReader, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected async Task<List<T>> GetKeyValueListAsync<T>(Type type, IDataReader dataReader)
|
||||
{
|
||||
List<T> result = new List<T>();
|
||||
while (await ((DbDataReader)dataReader).ReadAsync())
|
||||
{
|
||||
GetKeyValueList(type, dataReader, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void GetKeyValueList<T>(Type type, IDataReader dataReader, List<T> result)
|
||||
{
|
||||
if (UtilConstants.DicOO == type)
|
||||
{
|
||||
@ -96,6 +141,17 @@ namespace SqlSugar
|
||||
Check.Exception(true, ErrorMessage.NotSupportedDictionary);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected async Task<List<T>> GetArrayListAsync<T>(Type type, IDataReader dataReader)
|
||||
{
|
||||
List<T> result = new List<T>();
|
||||
int count = dataReader.FieldCount;
|
||||
var childType = type.GetElementType();
|
||||
while (await((DbDataReader)dataReader).ReadAsync())
|
||||
{
|
||||
GetArrayList(type, dataReader, result, count, childType);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -105,6 +161,15 @@ namespace SqlSugar
|
||||
int count = dataReader.FieldCount;
|
||||
var childType = type.GetElementType();
|
||||
while (dataReader.Read())
|
||||
{
|
||||
GetArrayList(type, dataReader, result, count, childType);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static void GetArrayList<T>(Type type, IDataReader dataReader, List<T> result, int count, Type childType)
|
||||
{
|
||||
object[] array = new object[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
@ -130,13 +195,27 @@ namespace SqlSugar
|
||||
else
|
||||
Check.Exception(true, ErrorMessage.NotSupportedArray);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected List<T> GetValueTypeList<T>(Type type, IDataReader dataReader)
|
||||
{
|
||||
List<T> result = new List<T>();
|
||||
while (dataReader.Read())
|
||||
{
|
||||
GetValueTypeList(type, dataReader, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
protected async Task<List<T>> GetValueTypeListAsync<T>(Type type, IDataReader dataReader)
|
||||
{
|
||||
List<T> result = new List<T>();
|
||||
while (await ((DbDataReader)dataReader).ReadAsync())
|
||||
{
|
||||
GetValueTypeList(type, dataReader, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void GetValueTypeList<T>(Type type, IDataReader dataReader, List<T> result)
|
||||
{
|
||||
var value = dataReader.GetValue(0);
|
||||
if (type == UtilConstants.GuidType)
|
||||
@ -156,7 +235,5 @@ namespace SqlSugar
|
||||
result.Add((T)Convert.ChangeType(value, UtilMethods.GetUnderType(type)));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,8 @@ using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public abstract partial class DbBindProvider : DbBindAccessory, IDbBind
|
||||
@ -201,6 +203,28 @@ namespace SqlSugar
|
||||
}
|
||||
}
|
||||
}
|
||||
public virtual async Task<List<T>> DataReaderToListAsync<T>(Type type, IDataReader dataReader)
|
||||
{
|
||||
using (dataReader)
|
||||
{
|
||||
if (type.Name.Contains("KeyValuePair"))
|
||||
{
|
||||
return await GetKeyValueListAsync<T>(type, dataReader);
|
||||
}
|
||||
else if (type.IsValueType() || type == UtilConstants.StringType || type == UtilConstants.ByteArrayType)
|
||||
{
|
||||
return await GetValueTypeListAsync<T>(type, dataReader);
|
||||
}
|
||||
else if (type.IsArray)
|
||||
{
|
||||
return await GetArrayListAsync<T>(type, dataReader);
|
||||
}
|
||||
else
|
||||
{
|
||||
return await GetEntityListAsync<T>(Context, dataReader);
|
||||
}
|
||||
}
|
||||
}
|
||||
public virtual List<T> DataReaderToListNoUsing<T>(Type type, IDataReader dataReader)
|
||||
{
|
||||
if (type.Name.Contains("KeyValuePair"))
|
||||
@ -220,6 +244,25 @@ namespace SqlSugar
|
||||
return GetEntityList<T>(Context, dataReader);
|
||||
}
|
||||
}
|
||||
public virtual Task<List<T>> DataReaderToListNoUsingAsync<T>(Type type, IDataReader dataReader)
|
||||
{
|
||||
if (type.Name.Contains("KeyValuePair"))
|
||||
{
|
||||
return GetKeyValueListAsync<T>(type, dataReader);
|
||||
}
|
||||
else if (type.IsValueType() || type == UtilConstants.StringType || type == UtilConstants.ByteArrayType)
|
||||
{
|
||||
return GetValueTypeListAsync<T>(type, dataReader);
|
||||
}
|
||||
else if (type.IsArray)
|
||||
{
|
||||
return GetArrayListAsync<T>(type, dataReader);
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetEntityListAsync<T>(Context, dataReader);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Throw rule
|
||||
|
@ -29,35 +29,36 @@ namespace SqlSugar
|
||||
return this.Context.EntityMaintenance.GetEntityInfo<T>();
|
||||
}
|
||||
}
|
||||
public int ExecuteCommand()
|
||||
{
|
||||
DeleteBuilder.EntityInfo = this.Context.EntityMaintenance.GetEntityInfo<T>();
|
||||
string sql = DeleteBuilder.ToSqlString();
|
||||
var paramters = DeleteBuilder.Parameters == null ? null : DeleteBuilder.Parameters.ToArray();
|
||||
RestoreMapping();
|
||||
AutoRemoveDataCache();
|
||||
Before(sql);
|
||||
var result = Db.ExecuteCommand(sql, paramters);
|
||||
After(sql);
|
||||
return result;
|
||||
}
|
||||
public void AddQueue()
|
||||
{
|
||||
var sqlObj = this.ToSql();
|
||||
this.Context.Queues.Add(sqlObj.Key, sqlObj.Value);
|
||||
}
|
||||
public int ExecuteCommand()
|
||||
{
|
||||
string sql;
|
||||
SugarParameter[] paramters;
|
||||
_ExecuteCommand(out sql, out paramters);
|
||||
var result = Db.ExecuteCommand(sql, paramters);
|
||||
After(sql);
|
||||
return result;
|
||||
}
|
||||
public bool ExecuteCommandHasChange()
|
||||
{
|
||||
return ExecuteCommand() > 0;
|
||||
}
|
||||
public Task<int> ExecuteCommandAsync()
|
||||
public async Task<int> ExecuteCommandAsync()
|
||||
{
|
||||
return Task.FromResult(ExecuteCommand());
|
||||
string sql;
|
||||
SugarParameter[] paramters;
|
||||
_ExecuteCommand(out sql, out paramters);
|
||||
var result =await Db.ExecuteCommandAsync(sql, paramters);
|
||||
After(sql);
|
||||
return result;
|
||||
}
|
||||
|
||||
public Task<bool> ExecuteCommandHasChangeAsync()
|
||||
public async Task<bool> ExecuteCommandHasChangeAsync()
|
||||
{
|
||||
return Task.FromResult(ExecuteCommandHasChange());
|
||||
return await ExecuteCommandAsync() > 0;
|
||||
}
|
||||
public IDeleteable<T> AS(string tableName)
|
||||
{
|
||||
@ -325,6 +326,15 @@ namespace SqlSugar
|
||||
return this.EntityInfo.Columns.Where(it => it.IsPrimarykey).Select(it => it.DbColumnName).ToList();
|
||||
}
|
||||
}
|
||||
private void _ExecuteCommand(out string sql, out SugarParameter[] paramters)
|
||||
{
|
||||
DeleteBuilder.EntityInfo = this.Context.EntityMaintenance.GetEntityInfo<T>();
|
||||
sql = DeleteBuilder.ToSqlString();
|
||||
paramters = DeleteBuilder.Parameters == null ? null : DeleteBuilder.Parameters.ToArray();
|
||||
RestoreMapping();
|
||||
AutoRemoveDataCache();
|
||||
Before(sql);
|
||||
}
|
||||
|
||||
protected virtual List<string> GetIdentityKeys()
|
||||
{
|
||||
|
@ -44,31 +44,11 @@ namespace SqlSugar
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (InsertBuilder.DbColumnInfoList.HasValue())
|
||||
{
|
||||
var pks = GetPrimaryKeys();
|
||||
foreach (var item in InsertBuilder.DbColumnInfoList)
|
||||
{
|
||||
var isPk = pks.Any(y => y.Equals(item.DbColumnName, StringComparison.CurrentCultureIgnoreCase)) || item.IsPrimarykey;
|
||||
if (isPk && item.PropertyType == UtilConstants.GuidType && item.Value.ObjToString() == Guid.Empty.ToString())
|
||||
{
|
||||
item.Value = Guid.NewGuid();
|
||||
if (InsertObjs.First().GetType().GetProperties().Any(it => it.Name == item.PropertyName))
|
||||
InsertObjs.First().GetType().GetProperties().First(it => it.Name == item.PropertyName).SetValue(InsertObjs.First(), item.Value, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
InsertBuilder.IsReturnIdentity = false;
|
||||
PreToSql();
|
||||
AutoRemoveDataCache();
|
||||
string sql = InsertBuilder.ToSqlString();
|
||||
RestoreMapping();
|
||||
Before(sql);
|
||||
string sql = _ExecuteCommand();
|
||||
var result = Ado.ExecuteCommand(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
|
||||
After(sql, null);
|
||||
return result;
|
||||
}
|
||||
|
||||
public virtual KeyValuePair<string, List<SugarParameter>> ToSql()
|
||||
{
|
||||
InsertBuilder.IsReturnIdentity = true;
|
||||
@ -84,32 +64,26 @@ namespace SqlSugar
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
InsertBuilder.IsReturnIdentity = true;
|
||||
PreToSql();
|
||||
AutoRemoveDataCache();
|
||||
string sql = InsertBuilder.ToSqlString();
|
||||
RestoreMapping();
|
||||
Before(sql);
|
||||
string sql = _ExecuteReturnIdentity();
|
||||
var result = Ado.GetInt(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
|
||||
After(sql, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public virtual long ExecuteReturnBigIdentity()
|
||||
{
|
||||
if (this.InsertObjs.Count() == 1 && this.InsertObjs.First() == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
InsertBuilder.IsReturnIdentity = true;
|
||||
PreToSql();
|
||||
AutoRemoveDataCache();
|
||||
string sql = InsertBuilder.ToSqlString();
|
||||
RestoreMapping();
|
||||
Before(sql);
|
||||
string sql = _ExecuteReturnBigIdentity();
|
||||
var result = Convert.ToInt64(Ado.GetScalar(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()));
|
||||
After(sql, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public virtual T ExecuteReturnEntity()
|
||||
{
|
||||
ExecuteCommandIdentityIntoEntity();
|
||||
@ -131,25 +105,60 @@ namespace SqlSugar
|
||||
this.Context.EntityMaintenance.GetProperty<T>(identityKey).SetValue(result, setValue, null);
|
||||
return idValue > 0;
|
||||
}
|
||||
public Task<int> ExecuteCommandAsync()
|
||||
|
||||
public async Task<int> ExecuteCommandAsync()
|
||||
{
|
||||
return Task.FromResult(ExecuteCommand());
|
||||
if (this.InsertObjs.Count() == 1 && this.InsertObjs.First() == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
public Task<int> ExecuteReturnIdentityAsync()
|
||||
{
|
||||
return Task.FromResult(ExecuteReturnIdentity());
|
||||
string sql = _ExecuteCommand();
|
||||
var result =await Ado.ExecuteCommandAsync(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
|
||||
After(sql, null);
|
||||
return result;
|
||||
}
|
||||
public Task<T> ExecuteReturnEntityAsync()
|
||||
public async Task<int> ExecuteReturnIdentityAsync()
|
||||
{
|
||||
return Task.FromResult(ExecuteReturnEntity());
|
||||
if (this.InsertObjs.Count() == 1 && this.InsertObjs.First() == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
public Task<bool> ExecuteCommandIdentityIntoEntityAsync()
|
||||
{
|
||||
return Task.FromResult(ExecuteCommandIdentityIntoEntity());
|
||||
string sql = _ExecuteReturnIdentity();
|
||||
var result =await Ado.GetIntAsync(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray());
|
||||
After(sql, result);
|
||||
return result;
|
||||
}
|
||||
public Task<long> ExecuteReturnBigIdentityAsync()
|
||||
public async Task<T> ExecuteReturnEntityAsync()
|
||||
{
|
||||
return Task.FromResult(ExecuteReturnBigIdentity());
|
||||
await ExecuteCommandIdentityIntoEntityAsync();
|
||||
return InsertObjs.First();
|
||||
}
|
||||
public async Task<bool> ExecuteCommandIdentityIntoEntityAsync()
|
||||
{
|
||||
var result = InsertObjs.First();
|
||||
var identityKeys = GetIdentityKeys();
|
||||
if (identityKeys.Count == 0) { return await this.ExecuteCommandAsync() > 0; }
|
||||
var idValue =await ExecuteReturnBigIdentityAsync();
|
||||
Check.Exception(identityKeys.Count > 1, "ExecuteCommandIdentityIntoEntity does not support multiple identity keys");
|
||||
var identityKey = identityKeys.First();
|
||||
object setValue = 0;
|
||||
if (idValue > int.MaxValue)
|
||||
setValue = idValue;
|
||||
else
|
||||
setValue = Convert.ToInt32(idValue);
|
||||
this.Context.EntityMaintenance.GetProperty<T>(identityKey).SetValue(result, setValue, null);
|
||||
return idValue > 0;
|
||||
}
|
||||
public async Task<long> ExecuteReturnBigIdentityAsync()
|
||||
{
|
||||
if (this.InsertObjs.Count() == 1 && this.InsertObjs.First() == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
string sql = _ExecuteReturnBigIdentity();
|
||||
var result = Convert.ToInt64(await Ado.GetScalarAsync(sql, InsertBuilder.Parameters == null ? null : InsertBuilder.Parameters.ToArray()));
|
||||
After(sql, result);
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -230,6 +239,51 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Protected Methods
|
||||
private string _ExecuteReturnBigIdentity()
|
||||
{
|
||||
InsertBuilder.IsReturnIdentity = true;
|
||||
PreToSql();
|
||||
AutoRemoveDataCache();
|
||||
string sql = InsertBuilder.ToSqlString();
|
||||
RestoreMapping();
|
||||
Before(sql);
|
||||
return sql;
|
||||
}
|
||||
private string _ExecuteReturnIdentity()
|
||||
{
|
||||
InsertBuilder.IsReturnIdentity = true;
|
||||
PreToSql();
|
||||
AutoRemoveDataCache();
|
||||
string sql = InsertBuilder.ToSqlString();
|
||||
RestoreMapping();
|
||||
Before(sql);
|
||||
return sql;
|
||||
}
|
||||
|
||||
private string _ExecuteCommand()
|
||||
{
|
||||
if (InsertBuilder.DbColumnInfoList.HasValue())
|
||||
{
|
||||
var pks = GetPrimaryKeys();
|
||||
foreach (var item in InsertBuilder.DbColumnInfoList)
|
||||
{
|
||||
var isPk = pks.Any(y => y.Equals(item.DbColumnName, StringComparison.CurrentCultureIgnoreCase)) || item.IsPrimarykey;
|
||||
if (isPk && item.PropertyType == UtilConstants.GuidType && item.Value.ObjToString() == Guid.Empty.ToString())
|
||||
{
|
||||
item.Value = Guid.NewGuid();
|
||||
if (InsertObjs.First().GetType().GetProperties().Any(it => it.Name == item.PropertyName))
|
||||
InsertObjs.First().GetType().GetProperties().First(it => it.Name == item.PropertyName).SetValue(InsertObjs.First(), item.Value, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
InsertBuilder.IsReturnIdentity = false;
|
||||
PreToSql();
|
||||
AutoRemoveDataCache();
|
||||
string sql = InsertBuilder.ToSqlString();
|
||||
RestoreMapping();
|
||||
Before(sql);
|
||||
return sql;
|
||||
}
|
||||
private void AutoRemoveDataCache()
|
||||
{
|
||||
var moreSetts = this.Context.CurrentConnectionConfig.MoreSettings;
|
||||
|
@ -16,7 +16,7 @@ namespace SqlSugar
|
||||
#region T1
|
||||
public partial class QueryableProvider<T> : QueryableAccessory, ISugarQueryable<T>
|
||||
{
|
||||
public ISqlSugarClient Context { get; set; }
|
||||
public SqlSugarProvider Context { get; set; }
|
||||
public IAdo Db { get { return Context.Ado; } }
|
||||
public IDbBind Bind { get { return this.Db.DbBind; } }
|
||||
public ISqlBuilder SqlBuilder { get; set; }
|
||||
@ -596,9 +596,9 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual int Count()
|
||||
{
|
||||
InitMapping();
|
||||
QueryBuilder.IsCount = true;
|
||||
int result = 0;
|
||||
MappingTableList expMapping;
|
||||
int result;
|
||||
_CountBegin(out expMapping, out result);
|
||||
if (IsCache)
|
||||
{
|
||||
var cacheService = this.Context.CurrentConnectionConfig.ConfigureExternalServices.DataInfoCacheService;
|
||||
@ -608,8 +608,7 @@ namespace SqlSugar
|
||||
{
|
||||
result = GetCount();
|
||||
}
|
||||
RestoreMapping();
|
||||
QueryBuilder.IsCount = false;
|
||||
_CountEnd(expMapping);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -753,18 +752,7 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual List<T> ToPageList(int pageIndex, int pageSize)
|
||||
{
|
||||
if (pageIndex == 0)
|
||||
pageIndex = 1;
|
||||
if (QueryBuilder.PartitionByValue.HasValue())
|
||||
{
|
||||
QueryBuilder.ExternalPageIndex = pageIndex;
|
||||
QueryBuilder.ExternalPageSize = pageSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
QueryBuilder.Skip = (pageIndex - 1) * pageSize;
|
||||
QueryBuilder.Take = pageSize;
|
||||
}
|
||||
pageIndex = _PageList(pageIndex, pageSize);
|
||||
return ToList();
|
||||
}
|
||||
public virtual List<T> ToPageList(int pageIndex, int pageSize, ref int totalNumber)
|
||||
@ -836,139 +824,262 @@ namespace SqlSugar
|
||||
return result;
|
||||
}
|
||||
#region Async methods
|
||||
public Task<T> SingleAsync()
|
||||
public async Task<T> SingleAsync()
|
||||
{
|
||||
return Task.FromResult(Single());
|
||||
if (QueryBuilder.OrderByValue.IsNullOrEmpty())
|
||||
{
|
||||
QueryBuilder.OrderByValue = QueryBuilder.DefaultOrderByTemplate;
|
||||
}
|
||||
var oldSkip = QueryBuilder.Skip;
|
||||
var oldTake = QueryBuilder.Take;
|
||||
var oldOrderBy = QueryBuilder.OrderByValue;
|
||||
QueryBuilder.Skip = null;
|
||||
QueryBuilder.Take = null;
|
||||
QueryBuilder.OrderByValue = null;
|
||||
var result =await this.ToListAsync();
|
||||
QueryBuilder.Skip = oldSkip;
|
||||
QueryBuilder.Take = oldTake;
|
||||
QueryBuilder.OrderByValue = oldOrderBy;
|
||||
if (result == null || result.Count == 0)
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
else if (result.Count == 2)
|
||||
{
|
||||
Check.Exception(true, ".Single() result must not exceed one . You can use.First()");
|
||||
return default(T);
|
||||
}
|
||||
else
|
||||
{
|
||||
return result.SingleOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
public Task<T> SingleAsync(Expression<Func<T, bool>> expression)
|
||||
public async Task<T> SingleAsync(Expression<Func<T, bool>> expression)
|
||||
{
|
||||
return Task.FromResult(Single(expression));
|
||||
_Where(expression);
|
||||
var result =await SingleAsync();
|
||||
this.QueryBuilder.WhereInfos.Remove(this.QueryBuilder.WhereInfos.Last());
|
||||
return result;
|
||||
}
|
||||
|
||||
public Task<T> FirstAsync()
|
||||
public async Task<T> FirstAsync()
|
||||
{
|
||||
return Task.FromResult(First());
|
||||
if (QueryBuilder.OrderByValue.IsNullOrEmpty())
|
||||
{
|
||||
QueryBuilder.OrderByValue = QueryBuilder.DefaultOrderByTemplate;
|
||||
}
|
||||
if (QueryBuilder.Skip.HasValue)
|
||||
{
|
||||
QueryBuilder.Take = 1;
|
||||
var list = await this.ToListAsync();
|
||||
return list.FirstOrDefault();
|
||||
}
|
||||
else
|
||||
{
|
||||
QueryBuilder.Skip = 0;
|
||||
QueryBuilder.Take = 1;
|
||||
var result =await this.ToListAsync();
|
||||
if (result.HasValue())
|
||||
return result.FirstOrDefault();
|
||||
else
|
||||
return default(T);
|
||||
}
|
||||
}
|
||||
|
||||
public Task<T> FirstAsync(Expression<Func<T, bool>> expression)
|
||||
public async Task<T> FirstAsync(Expression<Func<T, bool>> expression)
|
||||
{
|
||||
return Task.FromResult(First(expression));
|
||||
_Where(expression);
|
||||
var result = await FirstAsync();
|
||||
this.QueryBuilder.WhereInfos.Remove(this.QueryBuilder.WhereInfos.Last());
|
||||
return result;
|
||||
}
|
||||
|
||||
public Task<bool> AnyAsync(Expression<Func<T, bool>> expression)
|
||||
public async Task<bool> AnyAsync(Expression<Func<T, bool>> expression)
|
||||
{
|
||||
return Task.FromResult(Any(expression));
|
||||
_Where(expression);
|
||||
var result =await AnyAsync();
|
||||
this.QueryBuilder.WhereInfos.Remove(this.QueryBuilder.WhereInfos.Last());
|
||||
return result;
|
||||
}
|
||||
|
||||
public Task<bool> AnyAsync()
|
||||
public async Task<bool> AnyAsync()
|
||||
{
|
||||
return Task.FromResult(Any());
|
||||
return await this.CountAsync() > 0;
|
||||
}
|
||||
|
||||
public Task<int> CountAsync()
|
||||
public async Task<int> CountAsync()
|
||||
{
|
||||
return Task.FromResult(Count());
|
||||
MappingTableList expMapping;
|
||||
int result;
|
||||
_CountBegin(out expMapping, out result);
|
||||
if (IsCache)
|
||||
{
|
||||
var cacheService = this.Context.CurrentConnectionConfig.ConfigureExternalServices.DataInfoCacheService;
|
||||
result = CacheSchemeMain.GetOrCreate<int>(cacheService, this.QueryBuilder, () => { return GetCount(); }, CacheTime, this.Context);
|
||||
}
|
||||
public Task<int> CountAsync(Expression<Func<T, bool>> expression)
|
||||
else
|
||||
{
|
||||
return Task.FromResult(Count(expression));
|
||||
result =await GetCountAsync();
|
||||
}
|
||||
public Task<TResult> MaxAsync<TResult>(string maxField)
|
||||
_CountEnd(expMapping);
|
||||
return result;
|
||||
}
|
||||
public async Task<int> CountAsync(Expression<Func<T, bool>> expression)
|
||||
{
|
||||
return Task.FromResult(Max<TResult>(maxField));
|
||||
_Where(expression);
|
||||
var result =await CountAsync();
|
||||
this.QueryBuilder.WhereInfos.Remove(this.QueryBuilder.WhereInfos.Last());
|
||||
return result;
|
||||
}
|
||||
public async Task<TResult> MaxAsync<TResult>(string maxField)
|
||||
{
|
||||
this.Select(string.Format(QueryBuilder.MaxTemplate, maxField));
|
||||
var list = await this._ToListAsync<TResult>();
|
||||
var result =list.SingleOrDefault();
|
||||
return result;
|
||||
}
|
||||
|
||||
public Task<TResult> MaxAsync<TResult>(Expression<Func<T, TResult>> expression)
|
||||
{
|
||||
return Task.FromResult(Max<TResult>(expression));
|
||||
return _MaxAsync<TResult>(expression);
|
||||
}
|
||||
|
||||
public Task<TResult> MinAsync<TResult>(string minField)
|
||||
public async Task<TResult> MinAsync<TResult>(string minField)
|
||||
{
|
||||
return Task.FromResult(Min<TResult>(minField));
|
||||
this.Select(string.Format(QueryBuilder.MinTemplate, minField));
|
||||
var list = await this._ToListAsync<TResult>();
|
||||
var result = list.SingleOrDefault();
|
||||
return result;
|
||||
}
|
||||
|
||||
public Task<TResult> MinAsync<TResult>(Expression<Func<T, TResult>> expression)
|
||||
{
|
||||
return Task.FromResult(Min<TResult>(expression));
|
||||
return _MinAsync<TResult>(expression);
|
||||
}
|
||||
|
||||
public Task<TResult> SumAsync<TResult>(string sumField)
|
||||
public async Task<TResult> SumAsync<TResult>(string sumField)
|
||||
{
|
||||
return Task.FromResult(Sum<TResult>(sumField));
|
||||
this.Select(string.Format(QueryBuilder.SumTemplate, sumField));
|
||||
var list = await this._ToListAsync<TResult>();
|
||||
var result = list.SingleOrDefault();
|
||||
return result;
|
||||
}
|
||||
|
||||
public Task<TResult> SumAsync<TResult>(Expression<Func<T, TResult>> expression)
|
||||
{
|
||||
return Task.FromResult(Sum<TResult>(expression));
|
||||
return _SumAsync<TResult>(expression);
|
||||
}
|
||||
|
||||
public Task<TResult> AvgAsync<TResult>(string avgField)
|
||||
public async Task<TResult> AvgAsync<TResult>(string avgField)
|
||||
{
|
||||
return Task.FromResult(Avg<TResult>(avgField));
|
||||
this.Select(string.Format(QueryBuilder.AvgTemplate, avgField));
|
||||
var list = await this._ToListAsync<TResult>();
|
||||
var result = list.SingleOrDefault();
|
||||
return result;
|
||||
}
|
||||
|
||||
public Task<TResult> AvgAsync<TResult>(Expression<Func<T, TResult>> expression)
|
||||
{
|
||||
return Task.FromResult(Avg<TResult>(expression));
|
||||
return _AvgAsync<TResult>(expression);
|
||||
}
|
||||
|
||||
public Task<List<T>> ToListAsync()
|
||||
{
|
||||
return Task.FromResult(ToList());
|
||||
InitMapping();
|
||||
return _ToListAsync<T>();
|
||||
}
|
||||
|
||||
public Task<string> ToJsonAsync()
|
||||
{
|
||||
return Task.FromResult(ToJson());
|
||||
}
|
||||
|
||||
public Task<string> ToJsonPageAsync(int pageIndex, int pageSize)
|
||||
{
|
||||
return Task.FromResult(ToJsonPage(pageIndex, pageSize));
|
||||
}
|
||||
|
||||
public Task<string> ToJsonPageAsync(int pageIndex, int pageSize, ref int totalNumber)
|
||||
{
|
||||
return Task.FromResult(ToJsonPage(pageIndex, pageSize, ref totalNumber));
|
||||
}
|
||||
|
||||
public Task<DataTable> ToDataTableAsync()
|
||||
{
|
||||
return Task.FromResult(ToDataTable());
|
||||
}
|
||||
|
||||
public Task<DataTable> ToDataTablePageAsync(int pageIndex, int pageSize)
|
||||
{
|
||||
return Task.FromResult(ToDataTablePage(pageIndex, pageSize));
|
||||
}
|
||||
|
||||
public Task<DataTable> ToDataTablePageAsync(int pageIndex, int pageSize, ref int totalNumber)
|
||||
{
|
||||
return Task.FromResult(ToDataTablePage(pageIndex, pageSize, ref totalNumber));
|
||||
}
|
||||
|
||||
public Task<List<T>> ToPageListAsync(int pageIndex, int pageSize)
|
||||
{
|
||||
return Task.FromResult(ToPageList(pageIndex, pageSize));
|
||||
pageIndex = _PageList(pageIndex, pageSize);
|
||||
return ToListAsync();
|
||||
}
|
||||
public async Task<List<T>> ToPageListAsync(int pageIndex, int pageSize, RefAsync<int> totalNumber)
|
||||
{
|
||||
totalNumber.Value = await this.Clone().CountAsync();
|
||||
return await this.Clone().ToPageListAsync(pageIndex, pageSize);
|
||||
}
|
||||
public async Task<string> ToJsonAsync()
|
||||
{
|
||||
if (IsCache)
|
||||
{
|
||||
var cacheService = this.Context.CurrentConnectionConfig.ConfigureExternalServices.DataInfoCacheService;
|
||||
var result = CacheSchemeMain.GetOrCreate<string>(cacheService, this.QueryBuilder, () =>
|
||||
{
|
||||
return this.Context.Utilities.SerializeObject(this.ToList(), typeof(T));
|
||||
}, CacheTime, this.Context);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.Context.Utilities.SerializeObject(await this.ToListAsync(), typeof(T));
|
||||
}
|
||||
}
|
||||
public async Task<string> ToJsonPageAsync(int pageIndex, int pageSize)
|
||||
{
|
||||
return this.Context.Utilities.SerializeObject(await this.ToPageListAsync(pageIndex, pageSize), typeof(T));
|
||||
}
|
||||
public async Task<string> ToJsonPageAsync(int pageIndex, int pageSize, RefAsync<int> totalNumber)
|
||||
{
|
||||
totalNumber.Value = await this.Clone().CountAsync();
|
||||
return await this.Clone().ToJsonPageAsync(pageIndex, pageSize);
|
||||
}
|
||||
public async Task<DataTable> ToDataTableAsync()
|
||||
{
|
||||
InitMapping();
|
||||
var sqlObj = this.ToSql();
|
||||
RestoreMapping();
|
||||
DataTable result = null;
|
||||
if (IsCache)
|
||||
{
|
||||
var cacheService = this.Context.CurrentConnectionConfig.ConfigureExternalServices.DataInfoCacheService;
|
||||
result = CacheSchemeMain.GetOrCreate<DataTable>(cacheService, this.QueryBuilder, () => { return this.Db.GetDataTable(sqlObj.Key, sqlObj.Value.ToArray()); }, CacheTime, this.Context);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = await this.Db.GetDataTableAsync(sqlObj.Key, sqlObj.Value.ToArray());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public Task<DataTable> ToDataTablePageAsync(int pageIndex, int pageSize)
|
||||
{
|
||||
pageIndex = _PageList(pageIndex, pageSize);
|
||||
return ToDataTableAsync();
|
||||
}
|
||||
public async Task<DataTable> ToDataTablePageAsync(int pageIndex, int pageSize, RefAsync<int> totalNumber)
|
||||
{
|
||||
totalNumber.Value = await this.Clone().CountAsync();
|
||||
return await this.Clone().ToDataTablePageAsync(pageIndex, pageSize);
|
||||
}
|
||||
|
||||
public Task<List<T>> ToPageListAsync(int pageIndex, int pageSize, ref int totalNumber)
|
||||
{
|
||||
return Task.FromResult(ToPageList(pageIndex, pageSize, ref totalNumber));
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
//private void TaskStart<Type>(Task<Type> result)
|
||||
//{
|
||||
// if (this.Context.CurrentConnectionConfig.IsShardSameThread)
|
||||
// {
|
||||
// Check.Exception(true, "IsShardSameThread=true can't be used async method");
|
||||
// }
|
||||
// result.Start();
|
||||
//}
|
||||
private void _CountEnd(MappingTableList expMapping)
|
||||
{
|
||||
RestoreMapping();
|
||||
QueryBuilder.IsCount = false;
|
||||
if (expMapping.Count > 0)
|
||||
{
|
||||
if (this.QueryableMappingTableList == null)
|
||||
{
|
||||
this.QueryableMappingTableList = new MappingTableList();
|
||||
}
|
||||
this.QueryableMappingTableList.Add(expMapping.First());
|
||||
}
|
||||
}
|
||||
|
||||
private void _CountBegin(out MappingTableList expMapping, out int result)
|
||||
{
|
||||
expMapping = new MappingTableList();
|
||||
if (QueryBuilder.EntityName == "ExpandoObject" && this.Context.MappingTables.Any(it => it.EntityName == "ExpandoObject"))
|
||||
{
|
||||
expMapping.Add("ExpandoObject", this.Context.MappingTables.First(it => it.EntityName == "ExpandoObject").DbTableName);
|
||||
}
|
||||
InitMapping();
|
||||
QueryBuilder.IsCount = true;
|
||||
result = 0;
|
||||
}
|
||||
protected ISugarQueryable<TResult> _Select<TResult>(Expression expression)
|
||||
{
|
||||
QueryBuilder.CheckExpression(expression, "Select");
|
||||
@ -1005,6 +1116,23 @@ namespace SqlSugar
|
||||
return this;
|
||||
}
|
||||
}
|
||||
private int _PageList(int pageIndex, int pageSize)
|
||||
{
|
||||
if (pageIndex == 0)
|
||||
pageIndex = 1;
|
||||
if (QueryBuilder.PartitionByValue.HasValue())
|
||||
{
|
||||
QueryBuilder.ExternalPageIndex = pageIndex;
|
||||
QueryBuilder.ExternalPageSize = pageSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
QueryBuilder.Skip = (pageIndex - 1) * pageSize;
|
||||
QueryBuilder.Take = pageSize;
|
||||
}
|
||||
|
||||
return pageIndex;
|
||||
}
|
||||
protected ISugarQueryable<T> _GroupBy(Expression expression)
|
||||
{
|
||||
QueryBuilder.CheckExpression(expression, "GroupBy");
|
||||
@ -1035,6 +1163,15 @@ namespace SqlSugar
|
||||
QueryBuilder.SelectValue = null;
|
||||
return result;
|
||||
}
|
||||
protected async Task<TResult> _MinAsync<TResult>(Expression expression)
|
||||
{
|
||||
QueryBuilder.CheckExpression(expression, "Main");
|
||||
var isSingle = QueryBuilder.IsSingle();
|
||||
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
|
||||
var result = await MinAsync<TResult>(lamResult.GetResultString());
|
||||
QueryBuilder.SelectValue = null;
|
||||
return result;
|
||||
}
|
||||
protected TResult _Avg<TResult>(Expression expression)
|
||||
{
|
||||
QueryBuilder.CheckExpression(expression, "Avg");
|
||||
@ -1042,6 +1179,13 @@ namespace SqlSugar
|
||||
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
|
||||
return Avg<TResult>(lamResult.GetResultString());
|
||||
}
|
||||
protected async Task<TResult> _AvgAsync<TResult>(Expression expression)
|
||||
{
|
||||
QueryBuilder.CheckExpression(expression, "Avg");
|
||||
var isSingle = QueryBuilder.IsSingle();
|
||||
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
|
||||
return await AvgAsync<TResult>(lamResult.GetResultString());
|
||||
}
|
||||
protected TResult _Max<TResult>(Expression expression)
|
||||
{
|
||||
QueryBuilder.CheckExpression(expression, "Max");
|
||||
@ -1051,6 +1195,15 @@ namespace SqlSugar
|
||||
QueryBuilder.SelectValue = null;
|
||||
return reslut;
|
||||
}
|
||||
protected async Task<TResult> _MaxAsync<TResult>(Expression expression)
|
||||
{
|
||||
QueryBuilder.CheckExpression(expression, "Max");
|
||||
var isSingle = QueryBuilder.IsSingle();
|
||||
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
|
||||
var reslut =await MaxAsync<TResult>(lamResult.GetResultString());
|
||||
QueryBuilder.SelectValue = null;
|
||||
return reslut;
|
||||
}
|
||||
protected TResult _Sum<TResult>(Expression expression)
|
||||
{
|
||||
QueryBuilder.CheckExpression(expression, "Sum");
|
||||
@ -1060,6 +1213,15 @@ namespace SqlSugar
|
||||
QueryBuilder.SelectValue = null;
|
||||
return reslut;
|
||||
}
|
||||
protected async Task<TResult> _SumAsync<TResult>(Expression expression)
|
||||
{
|
||||
QueryBuilder.CheckExpression(expression, "Sum");
|
||||
var isSingle = QueryBuilder.IsSingle();
|
||||
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple);
|
||||
var reslut =await SumAsync<TResult>(lamResult.GetResultString());
|
||||
QueryBuilder.SelectValue = null;
|
||||
return reslut;
|
||||
}
|
||||
protected ISugarQueryable<T> _As(string tableName, string entityName)
|
||||
{
|
||||
IsAs = true;
|
||||
@ -1132,6 +1294,23 @@ namespace SqlSugar
|
||||
_Mapper(result);
|
||||
return result;
|
||||
}
|
||||
protected async Task<List<TResult>> _ToListAsync<TResult>()
|
||||
{
|
||||
List<TResult> result = null;
|
||||
var sqlObj = this.ToSql();
|
||||
if (IsCache)
|
||||
{
|
||||
var cacheService = this.Context.CurrentConnectionConfig.ConfigureExternalServices.DataInfoCacheService;
|
||||
result = CacheSchemeMain.GetOrCreate<List<TResult>>(cacheService, this.QueryBuilder, () => { return GetData<TResult>(sqlObj); }, CacheTime, this.Context);
|
||||
}
|
||||
else
|
||||
{
|
||||
result =await GetDataAsync<TResult>(sqlObj);
|
||||
}
|
||||
RestoreMapping();
|
||||
_Mapper(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
protected void _Mapper<TResult>(List<TResult> result)
|
||||
{
|
||||
@ -1519,6 +1698,15 @@ namespace SqlSugar
|
||||
var result = Context.Ado.GetInt(sql, QueryBuilder.Parameters.ToArray());
|
||||
return result;
|
||||
}
|
||||
protected async Task<int> GetCountAsync()
|
||||
{
|
||||
var sql = string.Empty;
|
||||
ToSqlBefore();
|
||||
sql = QueryBuilder.ToSqlString();
|
||||
sql = QueryBuilder.ToCountSql(sql);
|
||||
var result =Convert.ToInt32(await Context.Ado.GetScalarAsync(sql, QueryBuilder.Parameters.ToArray()));
|
||||
return result;
|
||||
}
|
||||
|
||||
private void ToSqlBefore()
|
||||
{
|
||||
@ -1535,6 +1723,22 @@ namespace SqlSugar
|
||||
var isComplexModel = QueryBuilder.IsComplexModel(sqlObj.Key);
|
||||
var entityType = typeof(TResult);
|
||||
var dataReader = this.Db.GetDataReader(sqlObj.Key, sqlObj.Value.ToArray());
|
||||
result = GetData<TResult>(isComplexModel, entityType, dataReader);
|
||||
return result;
|
||||
}
|
||||
protected async Task<List<TResult>> GetDataAsync<TResult>(KeyValuePair<string, List<SugarParameter>> sqlObj)
|
||||
{
|
||||
List<TResult> result;
|
||||
var isComplexModel = QueryBuilder.IsComplexModel(sqlObj.Key);
|
||||
var entityType = typeof(TResult);
|
||||
var dataReader = await this.Db.GetDataReaderAsync(sqlObj.Key, sqlObj.Value.ToArray());
|
||||
result =await GetDataAsync<TResult>(isComplexModel, entityType, dataReader);
|
||||
return result;
|
||||
}
|
||||
|
||||
private List<TResult> GetData<TResult>(bool isComplexModel, Type entityType, IDataReader dataReader)
|
||||
{
|
||||
List<TResult> result;
|
||||
if (entityType == UtilConstants.DynamicType)
|
||||
{
|
||||
result = this.Context.Utilities.DataReaderToExpandoObjectList(dataReader) as List<TResult>;
|
||||
@ -1554,6 +1758,29 @@ namespace SqlSugar
|
||||
SetContextModel(result, entityType);
|
||||
return result;
|
||||
}
|
||||
private async Task<List<TResult>> GetDataAsync<TResult>(bool isComplexModel, Type entityType, IDataReader dataReader)
|
||||
{
|
||||
List<TResult> result;
|
||||
if (entityType == UtilConstants.DynamicType)
|
||||
{
|
||||
result =await this.Context.Utilities.DataReaderToExpandoObjectListAsync(dataReader) as List<TResult>;
|
||||
}
|
||||
else if (entityType == UtilConstants.ObjType)
|
||||
{
|
||||
var expObj = await this.Context.Utilities.DataReaderToExpandoObjectListAsync(dataReader);
|
||||
result = expObj.Select(it => ((TResult)(object)it)).ToList();
|
||||
}
|
||||
else if (entityType.IsAnonymousType() || isComplexModel)
|
||||
{
|
||||
result =await this.Context.Utilities.DataReaderToListAsync<TResult>(dataReader);
|
||||
}
|
||||
else
|
||||
{
|
||||
result =await this.Bind.DataReaderToListAsync<TResult>(entityType, dataReader);
|
||||
}
|
||||
SetContextModel(result, entityType);
|
||||
return result;
|
||||
}
|
||||
|
||||
protected void _InQueryable(Expression expression, KeyValuePair<string, List<SugarParameter>> sqlObj)
|
||||
{
|
||||
@ -1618,6 +1845,7 @@ namespace SqlSugar
|
||||
{
|
||||
var contextProperty = item.GetType().GetProperty("Context");
|
||||
SqlSugarProvider newClient = this.Context.Utilities.CopyContext();
|
||||
newClient.Ado.IsDisableMasterSlaveSeparation = true;
|
||||
if (newClient.CurrentConnectionConfig.AopEvents == null)
|
||||
newClient.CurrentConnectionConfig.AopEvents = new AopEvents();
|
||||
contextProperty.SetValue(item, newClient, null);
|
||||
@ -1625,23 +1853,6 @@ namespace SqlSugar
|
||||
}
|
||||
}
|
||||
}
|
||||
//protected ISugarQueryable<T> CopyQueryable()
|
||||
//{
|
||||
// var asyncContext = this.Context.Utilities.CopyContext(true);
|
||||
// asyncContext.IsAsyncMethod = true;
|
||||
// asyncContext.CurrentConnectionConfig.IsAutoCloseConnection = true;
|
||||
// var asyncQueryable = asyncContext.Queryable<ExpandoObject>().Select<T>(string.Empty).WithCacheIF(IsCache, CacheTime);
|
||||
// if (this.MapperAction != null)
|
||||
// asyncQueryable.Mapper(MapperAction);
|
||||
// if (this.MapperActionWithCache != null)
|
||||
// asyncQueryable.Mapper(MapperActionWithCache);
|
||||
// if (this.Mappers != null && ((asyncQueryable as QueryableProvider<T>)!=null))
|
||||
// {
|
||||
// (asyncQueryable as QueryableProvider<T>).Mappers = this.Mappers;
|
||||
// }
|
||||
// CopyQueryBuilder(asyncQueryable.QueryBuilder); return asyncQueryable;
|
||||
//}
|
||||
|
||||
protected void CopyQueryBuilder(QueryBuilder asyncQueryableBuilder)
|
||||
{
|
||||
var pars = new List<SugarParameter>();
|
||||
|
@ -10,7 +10,7 @@ namespace SqlSugar
|
||||
public partial class SqlSugarProvider
|
||||
{
|
||||
#region Properties
|
||||
public ISqlSugarClient Context
|
||||
public SqlSugarProvider Context
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -39,7 +39,7 @@ namespace SqlSugar
|
||||
public Dictionary<string, object> _TempItems;
|
||||
public QueueList _Queues;
|
||||
protected ISqlBuilder _SqlBuilder;
|
||||
protected ISqlSugarClient _Context { get; set; }
|
||||
protected SqlSugarProvider _Context { get; set; }
|
||||
protected EntityMaintenance _EntityProvider;
|
||||
protected IAdo _Ado;
|
||||
protected ILambdaExpressions _LambdaExpressions;
|
||||
|
@ -794,73 +794,65 @@ namespace SqlSugar
|
||||
return SaveQueuesProvider(isTran, (sql, parameters) => { return this.Ado.ExecuteCommand(sql, parameters); });
|
||||
}
|
||||
|
||||
public Task<int> SaveQueuesAsync(bool isTran = true)
|
||||
public async Task<int> SaveQueuesAsync(bool isTran = true)
|
||||
{
|
||||
var result =Task.FromResult(SaveQueues(isTran));
|
||||
return result;
|
||||
return await SaveQueuesProviderAsync(isTran, (sql, parameters) => { return this.Ado.ExecuteCommandAsync(sql, parameters); });
|
||||
}
|
||||
public List<T> SaveQueues<T>(bool isTran = true)
|
||||
{
|
||||
return SaveQueuesProvider(isTran, (sql, parameters) => { return this.Ado.SqlQuery<T>(sql, parameters); });
|
||||
}
|
||||
public Task<List<T>> SaveQueuesAsync<T>(bool isTran = true)
|
||||
public async Task<List<T>> SaveQueuesAsync<T>(bool isTran = true)
|
||||
{
|
||||
var result = Task.FromResult(SaveQueues<T>(isTran));
|
||||
return result;
|
||||
return await SaveQueuesProviderAsync(isTran, (sql, parameters) => { return this.Ado.SqlQueryAsync<T>(sql, parameters); });
|
||||
}
|
||||
public Tuple<List<T>, List<T2>> SaveQueues<T, T2>(bool isTran = true)
|
||||
{
|
||||
return SaveQueuesProvider(isTran, (sql, parameters) => { return this.Ado.SqlQuery<T, T2>(sql, parameters); });
|
||||
}
|
||||
public Task<Tuple<List<T>, List<T2>>> SaveQueuesAsync<T, T2>(bool isTran = true)
|
||||
public async Task<Tuple<List<T>, List<T2>>> SaveQueuesAsync<T, T2>(bool isTran = true)
|
||||
{
|
||||
var result = Task.FromResult(SaveQueues<T,T2>(isTran));
|
||||
return result;
|
||||
return await SaveQueuesProviderAsync(isTran, (sql, parameters) => { return this.Ado.SqlQueryAsync<T, T2>(sql, parameters); });
|
||||
}
|
||||
public Tuple<List<T>, List<T2>, List<T3>> SaveQueues<T, T2, T3>(bool isTran = true)
|
||||
{
|
||||
return SaveQueuesProvider(isTran, (sql, parameters) => { return this.Ado.SqlQuery<T, T2, T3>(sql, parameters); });
|
||||
}
|
||||
public Task<Tuple<List<T>, List<T2>, List<T3>>> SaveQueuesAsync<T, T2, T3>(bool isTran = true)
|
||||
public async Task<Tuple<List<T>, List<T2>, List<T3>>> SaveQueuesAsync<T, T2, T3>(bool isTran = true)
|
||||
{
|
||||
var result = Task.FromResult(SaveQueues<T, T2,T3>(isTran));
|
||||
return result;
|
||||
return await SaveQueuesProviderAsync(isTran, (sql, parameters) => { return this.Ado.SqlQueryAsync<T, T2, T3>(sql, parameters); });
|
||||
}
|
||||
public Tuple<List<T>, List<T2>, List<T3>, List<T4>> SaveQueues<T, T2, T3, T4>(bool isTran = true)
|
||||
{
|
||||
return SaveQueuesProvider(isTran, (sql, parameters) => { return this.Ado.SqlQuery<T, T2, T3, T4>(sql, parameters); });
|
||||
}
|
||||
public Task<Tuple<List<T>, List<T2>, List<T3>, List<T4>>> SaveQueuesAsync<T, T2, T3, T4>(bool isTran = true)
|
||||
public async Task<Tuple<List<T>, List<T2>, List<T3>, List<T4>>> SaveQueuesAsync<T, T2, T3, T4>(bool isTran = true)
|
||||
{
|
||||
var result = Task.FromResult(SaveQueues<T, T2, T3,T4>(isTran));
|
||||
return result;
|
||||
return await SaveQueuesProviderAsync(isTran, (sql, parameters) => { return this.Ado.SqlQueryAsync<T, T2, T3, T4>(sql, parameters); });
|
||||
}
|
||||
public Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>> SaveQueues<T, T2, T3, T4, T5>(bool isTran = true)
|
||||
{
|
||||
return SaveQueuesProvider(isTran, (sql, parameters) => { return this.Ado.SqlQuery<T, T2, T3, T4, T5>(sql, parameters); });
|
||||
}
|
||||
public Task<Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>>> SaveQueuesAsync<T, T2, T3, T4, T5>(bool isTran = true)
|
||||
public async Task<Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>>> SaveQueuesAsync<T, T2, T3, T4, T5>(bool isTran = true)
|
||||
{
|
||||
var result = Task.FromResult(SaveQueues<T, T2, T3, T4,T5>(isTran));
|
||||
return result;
|
||||
return await SaveQueuesProviderAsync(isTran, (sql, parameters) => { return this.Ado.SqlQueryAsync<T, T2, T3, T4, T5>(sql, parameters); });
|
||||
}
|
||||
public Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>, List<T6>> SaveQueues<T, T2, T3, T4, T5, T6>(bool isTran = true)
|
||||
{
|
||||
return SaveQueuesProvider(isTran, (sql, parameters) => { return this.Ado.SqlQuery<T, T2, T3, T4, T5, T6>(sql, parameters); });
|
||||
}
|
||||
public Task<Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>, List<T6>>> SaveQueuesAsync<T, T2, T3, T4, T5, T6>(bool isTran = true)
|
||||
public async Task<Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>, List<T6>>> SaveQueuesAsync<T, T2, T3, T4, T5, T6>(bool isTran = true)
|
||||
{
|
||||
var result = Task.FromResult(SaveQueues<T, T2, T3, T4, T5,T6>(isTran));
|
||||
return result;
|
||||
return await SaveQueuesProviderAsync(isTran, (sql, parameters) => { return this.Ado.SqlQueryAsync<T, T2, T3, T4, T5, T6>(sql, parameters); });
|
||||
}
|
||||
public Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>, List<T6>, List<T7>> SaveQueues<T, T2, T3, T4, T5, T6, T7>(bool isTran = true)
|
||||
{
|
||||
return SaveQueuesProvider(isTran, (sql, parameters) => { return this.Ado.SqlQuery<T, T2, T3, T4, T5, T6, T7>(sql, parameters); });
|
||||
}
|
||||
public Task<Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>, List<T6>, List<T7>>> SaveQueuesAsync<T, T2, T3, T4, T5, T6, T7>(bool isTran = true)
|
||||
public async Task<Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>, List<T6>, List<T7>>> SaveQueuesAsync<T, T2, T3, T4, T5, T6, T7>(bool isTran = true)
|
||||
{
|
||||
var result = Task.FromResult(SaveQueues<T, T2, T3, T4, T5, T6,T7>(isTran));
|
||||
return result;
|
||||
return await SaveQueuesProviderAsync(isTran, (sql, parameters) => { return this.Ado.SqlQueryAsync<T, T2, T3, T4, T5, T6, T7>(sql, parameters); });
|
||||
}
|
||||
public void AddQueue(string sql, object parsmeters=null)
|
||||
{
|
||||
@ -888,6 +880,58 @@ namespace SqlSugar
|
||||
}
|
||||
public QueueList Queues { get { if (_Queues == null) { _Queues = new QueueList(); } return _Queues; } set => _Queues = value; }
|
||||
|
||||
|
||||
|
||||
private async Task<T> SaveQueuesProviderAsync<T>(bool isTran, Func<string, List<SugarParameter>, Task<T>> func)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (this.CurrentConnectionConfig.DbType == DbType.Oracle)
|
||||
{
|
||||
throw new Exception("Oracle no support SaveQueues");
|
||||
}
|
||||
if (this.Queues == null || this.Queues.Count == 0) return default(T);
|
||||
isTran = isTran && this.Ado.Transaction == null;
|
||||
if (isTran) this.Ado.BeginTran();
|
||||
StringBuilder sqlBuilder = new StringBuilder();
|
||||
var parsmeters = new List<SugarParameter>();
|
||||
var index = 1;
|
||||
if (this.Queues.HasValue())
|
||||
{
|
||||
foreach (var item in Queues)
|
||||
{
|
||||
if (item.Sql == null)
|
||||
item.Sql = string.Empty;
|
||||
if (item.Parameters == null)
|
||||
item.Parameters = new SugarParameter[] { };
|
||||
var itemParsmeters = item.Parameters.OrderByDescending(it => it.ParameterName.Length).ToList();
|
||||
List<SugarParameter> addParameters = new List<SugarParameter>();
|
||||
var itemSql = item.Sql;
|
||||
foreach (var itemParameter in itemParsmeters)
|
||||
{
|
||||
var newName = itemParameter.ParameterName + "_q_" + index;
|
||||
SugarParameter parameter = new SugarParameter(newName, itemParameter.Value);
|
||||
parameter.DbType = itemParameter.DbType;
|
||||
itemSql = UtilMethods.ReplaceSqlParameter(itemSql, itemParameter, newName);
|
||||
addParameters.Add(parameter);
|
||||
}
|
||||
parsmeters.AddRange(addParameters);
|
||||
itemSql = itemSql.TrimEnd(';') + ";";
|
||||
sqlBuilder.AppendLine(itemSql);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
this.Queues.Clear();
|
||||
var result =await func(sqlBuilder.ToString(), parsmeters);
|
||||
if (isTran) this.Ado.CommitTran();
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (isTran) this.Ado.RollbackTran();
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
private T SaveQueuesProvider<T>(bool isTran, Func<string, List<SugarParameter>, T> func)
|
||||
{
|
||||
try
|
||||
|
@ -51,29 +51,25 @@ namespace SqlSugar
|
||||
}
|
||||
public virtual int ExecuteCommand()
|
||||
{
|
||||
PreToSql();
|
||||
AutoRemoveDataCache();
|
||||
Check.Exception(UpdateBuilder.WhereValues.IsNullOrEmpty() && GetPrimaryKeys().IsNullOrEmpty(), "You cannot have no primary key and no conditions");
|
||||
string sql = UpdateBuilder.ToSqlString();
|
||||
ValidateVersion();
|
||||
RestoreMapping();
|
||||
Before(sql);
|
||||
string sql = _ExecuteCommand();
|
||||
var result = this.Ado.ExecuteCommand(sql, UpdateBuilder.Parameters == null ? null : UpdateBuilder.Parameters.ToArray());
|
||||
After(sql);
|
||||
return result;
|
||||
}
|
||||
|
||||
public bool ExecuteCommandHasChange()
|
||||
{
|
||||
return this.ExecuteCommand() > 0;
|
||||
}
|
||||
public Task<int> ExecuteCommandAsync()
|
||||
public async Task<int> ExecuteCommandAsync()
|
||||
{
|
||||
return Task.FromResult(ExecuteCommand());
|
||||
string sql = _ExecuteCommand();
|
||||
var result =await this.Ado.ExecuteCommandAsync(sql, UpdateBuilder.Parameters == null ? null : UpdateBuilder.Parameters.ToArray());
|
||||
After(sql);
|
||||
return result;
|
||||
}
|
||||
public Task<bool> ExecuteCommandHasChangeAsync()
|
||||
public async Task<bool> ExecuteCommandHasChangeAsync()
|
||||
{
|
||||
return Task.FromResult(ExecuteCommandHasChange());
|
||||
return await this.ExecuteCommandAsync() > 0;
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -195,7 +191,6 @@ namespace SqlSugar
|
||||
}
|
||||
|
||||
|
||||
|
||||
public IUpdateable<T> UpdateColumns(Expression<Func<T, object>> columns)
|
||||
{
|
||||
var updateColumns = UpdateBuilder.GetExpressionValue(columns, ResolveExpressType.ArraySingle).GetResultArray().Select(it => this.SqlBuilder.GetNoTranslationColumnName(it)).ToList();
|
||||
@ -374,6 +369,17 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Helper
|
||||
private string _ExecuteCommand()
|
||||
{
|
||||
PreToSql();
|
||||
AutoRemoveDataCache();
|
||||
Check.Exception(UpdateBuilder.WhereValues.IsNullOrEmpty() && GetPrimaryKeys().IsNullOrEmpty(), "You cannot have no primary key and no conditions");
|
||||
string sql = UpdateBuilder.ToSqlString();
|
||||
ValidateVersion();
|
||||
RestoreMapping();
|
||||
Before(sql);
|
||||
return sql;
|
||||
}
|
||||
private void AutoRemoveDataCache()
|
||||
{
|
||||
var moreSetts = this.Context.CurrentConnectionConfig.MoreSettings;
|
||||
@ -591,43 +597,7 @@ namespace SqlSugar
|
||||
this.Context.MappingTables = OldMappingTableList;
|
||||
}
|
||||
}
|
||||
//private void TaskStart<Type>(Task<Type> result)
|
||||
//{
|
||||
// if (this.Context.CurrentConnectionConfig.IsShardSameThread)
|
||||
// {
|
||||
// Check.Exception(true, "IsShardSameThread=true can't be used async method");
|
||||
// }
|
||||
// result.Start();
|
||||
//}
|
||||
//private IUpdateable<T> CopyUpdateable()
|
||||
//{
|
||||
// var asyncContext = this.Context.Utilities.CopyContext(true);
|
||||
// asyncContext.CurrentConnectionConfig.IsAutoCloseConnection = true;
|
||||
// asyncContext.IsAsyncMethod = true;
|
||||
|
||||
// var asyncUpdateable = asyncContext.Updateable<T>(this.UpdateObjs);
|
||||
// var asyncUpdateableBuilder = asyncUpdateable.UpdateBuilder;
|
||||
// asyncUpdateableBuilder.DbColumnInfoList = this.UpdateBuilder.DbColumnInfoList;
|
||||
// asyncUpdateableBuilder.IsNoUpdateNull = this.UpdateBuilder.IsNoUpdateNull;
|
||||
// asyncUpdateableBuilder.Parameters = this.UpdateBuilder.Parameters;
|
||||
// asyncUpdateableBuilder.sql = this.UpdateBuilder.sql;
|
||||
// asyncUpdateableBuilder.WhereValues = this.UpdateBuilder.WhereValues;
|
||||
// asyncUpdateableBuilder.TableWithString = this.UpdateBuilder.TableWithString;
|
||||
// asyncUpdateableBuilder.TableName = this.UpdateBuilder.TableName;
|
||||
// asyncUpdateableBuilder.PrimaryKeys = this.UpdateBuilder.PrimaryKeys;
|
||||
// asyncUpdateableBuilder.IsOffIdentity = this.UpdateBuilder.IsOffIdentity;
|
||||
// asyncUpdateableBuilder.SetValues = this.UpdateBuilder.SetValues;
|
||||
// if (this.IsWhereColumns)
|
||||
// {
|
||||
// (asyncUpdateable as UpdateableProvider<T>).WhereColumnList = this.WhereColumnList;
|
||||
// (asyncUpdateable as UpdateableProvider<T>).IsWhereColumns = this.IsWhereColumns;
|
||||
// }
|
||||
// if (this.RemoveCacheFunc != null)
|
||||
// {
|
||||
// asyncUpdateable.RemoveDataCache();
|
||||
// }
|
||||
// return asyncUpdateable;
|
||||
//}
|
||||
|
||||
private void ValidateVersion()
|
||||
{
|
||||
|
@ -7,7 +7,7 @@ namespace SqlSugar
|
||||
{
|
||||
internal class CacheKeyBuider
|
||||
{
|
||||
public static CacheKey GetKey(ISqlSugarClient context, QueryBuilder queryBuilder)
|
||||
public static CacheKey GetKey(SqlSugarProvider context, QueryBuilder queryBuilder)
|
||||
{
|
||||
CacheKey result = new CacheKey();
|
||||
result.Database = context.Context.Ado.Connection.Database;
|
||||
|
@ -7,7 +7,7 @@ namespace SqlSugar
|
||||
{
|
||||
internal class CacheSchemeMain
|
||||
{
|
||||
public static T GetOrCreate<T>(ICacheService cacheService, QueryBuilder queryBuilder, Func<T> getData, int cacheDurationInSeconds, ISqlSugarClient context)
|
||||
public static T GetOrCreate<T>(ICacheService cacheService, QueryBuilder queryBuilder, Func<T> getData, int cacheDurationInSeconds, SqlSugarProvider context)
|
||||
{
|
||||
CacheKey key = CacheKeyBuider.GetKey(context, queryBuilder);
|
||||
string keyString = key.ToString();
|
||||
|
22
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/AsyncRef.cs
Normal file
22
Src/Asp.NetCore2/SqlSeverTest/SqlSugar/Entities/AsyncRef.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public class RefAsync<T>
|
||||
{
|
||||
public RefAsync() { }
|
||||
public RefAsync(T value) { Value = value; }
|
||||
public T Value { get; set; }
|
||||
public override string ToString()
|
||||
{
|
||||
T value = Value;
|
||||
return value == null ? "" : value.ToString();
|
||||
}
|
||||
public static implicit operator T(RefAsync<T> r) { return r.Value; }
|
||||
public static implicit operator RefAsync<T>(T value) { return new RefAsync<T>(value); }
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ namespace SqlSugar
|
||||
{
|
||||
public class SugarTenant
|
||||
{
|
||||
public ISqlSugarClient Context { get; set; }
|
||||
public SqlSugarProvider Context { get; set; }
|
||||
public ConnectionConfig ConnectionConfig { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Dynamic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
@ -60,6 +61,64 @@ namespace SqlSugar
|
||||
return result;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
///DataReader to Dynamic List
|
||||
/// </summary>
|
||||
/// <param name="reader"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<ExpandoObject>> DataReaderToExpandoObjectListAsync(IDataReader reader)
|
||||
{
|
||||
using (reader)
|
||||
{
|
||||
List<ExpandoObject> result = new List<ExpandoObject>();
|
||||
if (reader != null && !reader.IsClosed)
|
||||
{
|
||||
while (await((DbDataReader)reader).ReadAsync())
|
||||
{
|
||||
result.Add(DataReaderToExpandoObject(reader));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///DataReader to Dynamic List
|
||||
/// </summary>
|
||||
/// <param name="reader"></param>
|
||||
/// <returns></returns>
|
||||
public List<ExpandoObject> DataReaderToExpandoObjectListNoUsing(IDataReader reader)
|
||||
{
|
||||
List<ExpandoObject> result = new List<ExpandoObject>();
|
||||
if (reader != null && !reader.IsClosed)
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
result.Add(DataReaderToExpandoObject(reader));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///DataReader to Dynamic List
|
||||
/// </summary>
|
||||
/// <param name="reader"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<ExpandoObject>> DataReaderToExpandoObjectListAsyncNoUsing(IDataReader reader)
|
||||
{
|
||||
List<ExpandoObject> result = new List<ExpandoObject>();
|
||||
if (reader != null && !reader.IsClosed)
|
||||
{
|
||||
while (await ((DbDataReader)reader).ReadAsync())
|
||||
{
|
||||
result.Add(DataReaderToExpandoObject(reader));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///DataReader to DataReaderToDictionary
|
||||
@ -129,6 +188,86 @@ namespace SqlSugar
|
||||
if (reader != null && !reader.IsClosed)
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
Dictionary<string, object> result = DataReaderToList(reader, tType, classProperties, reval);
|
||||
var stringValue = SerializeObject(result);
|
||||
reval.Add((T)DeserializeObject<T>(stringValue));
|
||||
}
|
||||
}
|
||||
return reval;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// DataReaderToList
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="reader"></param>
|
||||
/// <returns></returns>
|
||||
public List<T> DataReaderToListNoUsing<T>(IDataReader reader)
|
||||
{
|
||||
var tType = typeof(T);
|
||||
var classProperties = tType.GetProperties().ToList();
|
||||
var reval = new List<T>();
|
||||
if (reader != null && !reader.IsClosed)
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
Dictionary<string, object> result = DataReaderToList(reader, tType, classProperties, reval);
|
||||
var stringValue = SerializeObject(result);
|
||||
reval.Add((T)DeserializeObject<T>(stringValue));
|
||||
}
|
||||
}
|
||||
return reval;
|
||||
}
|
||||
/// <summary>
|
||||
/// DataReaderToList
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="reader"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<T>> DataReaderToListAsync<T>(IDataReader reader)
|
||||
{
|
||||
using (reader)
|
||||
{
|
||||
var tType = typeof(T);
|
||||
var classProperties = tType.GetProperties().ToList();
|
||||
var reval = new List<T>();
|
||||
if (reader != null && !reader.IsClosed)
|
||||
{
|
||||
while (await ((DbDataReader)reader).ReadAsync())
|
||||
{
|
||||
Dictionary<string, object> result = DataReaderToList(reader, tType, classProperties, reval);
|
||||
var stringValue = SerializeObject(result);
|
||||
reval.Add((T)DeserializeObject<T>(stringValue));
|
||||
}
|
||||
}
|
||||
return reval;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// DataReaderToList
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="reader"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<T>> DataReaderToListAsyncNoUsing<T>(IDataReader reader)
|
||||
{
|
||||
var tType = typeof(T);
|
||||
var classProperties = tType.GetProperties().ToList();
|
||||
var reval = new List<T>();
|
||||
if (reader != null && !reader.IsClosed)
|
||||
{
|
||||
while (await ((DbDataReader)reader).ReadAsync())
|
||||
{
|
||||
Dictionary<string, object> result = DataReaderToList(reader, tType, classProperties, reval);
|
||||
var stringValue = SerializeObject(result);
|
||||
reval.Add((T)DeserializeObject<T>(stringValue));
|
||||
}
|
||||
}
|
||||
return reval;
|
||||
}
|
||||
|
||||
private Dictionary<string, object> DataReaderToList<T>(IDataReader reader, Type tType, List<PropertyInfo> classProperties, List<T> reval)
|
||||
{
|
||||
var readerValues = DataReaderToDictionary(reader, tType);
|
||||
var result = new Dictionary<string, object>();
|
||||
@ -176,12 +315,8 @@ namespace SqlSugar
|
||||
}
|
||||
}
|
||||
}
|
||||
var stringValue = SerializeObject(result);
|
||||
reval.Add((T)DeserializeObject<T>(stringValue));
|
||||
}
|
||||
}
|
||||
return reval;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private Dictionary<string, object> DataReaderToDynamicList_Part<T>(Dictionary<string, object> readerValues, PropertyInfo item, List<T> reval)
|
||||
|
@ -33,38 +33,100 @@ namespace SqlSugar
|
||||
void SetCommandToAdapter(IDataAdapter adapter, DbCommand command);
|
||||
IDataAdapter GetAdapter();
|
||||
DbCommand GetCommand(string sql, SugarParameter[] parameters);
|
||||
|
||||
|
||||
DataTable GetDataTable(string sql, object parameters);
|
||||
DataTable GetDataTable(string sql, params SugarParameter[] parameters);
|
||||
DataTable GetDataTable(string sql, List<SugarParameter> parameters);
|
||||
|
||||
Task<DataTable> GetDataTableAsync(string sql, object parameters);
|
||||
Task<DataTable> GetDataTableAsync(string sql, params SugarParameter[] parameters);
|
||||
Task<DataTable> GetDataTableAsync(string sql, List<SugarParameter> parameters);
|
||||
|
||||
DataSet GetDataSetAll(string sql, object parameters);
|
||||
DataSet GetDataSetAll(string sql, params SugarParameter[] parameters);
|
||||
DataSet GetDataSetAll(string sql, List<SugarParameter> parameters);
|
||||
|
||||
Task<DataSet> GetDataSetAllAsync(string sql, object parameters);
|
||||
Task<DataSet> GetDataSetAllAsync(string sql, params SugarParameter[] parameters);
|
||||
Task<DataSet> GetDataSetAllAsync(string sql, List<SugarParameter> parameters);
|
||||
|
||||
IDataReader GetDataReader(string sql, object parameters);
|
||||
IDataReader GetDataReader(string sql, params SugarParameter[] parameters);
|
||||
IDataReader GetDataReader(string sql, List<SugarParameter> parameters);
|
||||
|
||||
|
||||
Task<IDataReader> GetDataReaderAsync(string sql, object parameters);
|
||||
Task<IDataReader> GetDataReaderAsync(string sql, params SugarParameter[] parameters);
|
||||
Task<IDataReader> GetDataReaderAsync(string sql, List<SugarParameter> parameters);
|
||||
Task<IDataReader> GetDataReaderNoCloseAsync(string sql, params SugarParameter[] parameters);
|
||||
|
||||
object GetScalar(string sql, object parameters);
|
||||
object GetScalar(string sql, params SugarParameter[] parameters);
|
||||
object GetScalar(string sql, List<SugarParameter> parameters);
|
||||
|
||||
Task<object> GetScalarAsync(string sql, object parameters);
|
||||
Task<object> GetScalarAsync(string sql, params SugarParameter[] parameters);
|
||||
Task<object> GetScalarAsync(string sql, List<SugarParameter> parameters);
|
||||
|
||||
int ExecuteCommand(string sql, object parameters);
|
||||
int ExecuteCommand(string sql, params SugarParameter[] parameters);
|
||||
int ExecuteCommand(string sql, List<SugarParameter> parameters);
|
||||
|
||||
Task<int> ExecuteCommandAsync(string sql, params SugarParameter[] parameters);
|
||||
Task<int> ExecuteCommandAsync(string sql, object parameters);
|
||||
Task<int> ExecuteCommandAsync(string sql, List<SugarParameter> parameters);
|
||||
|
||||
string GetString(string sql, object parameters);
|
||||
string GetString(string sql, params SugarParameter[] parameters);
|
||||
string GetString(string sql, List<SugarParameter> parameters);
|
||||
Task<string> GetStringAsync(string sql, object parameters);
|
||||
Task<string> GetStringAsync(string sql, params SugarParameter[] parameters);
|
||||
Task<string> GetStringAsync(string sql, List<SugarParameter> parameters);
|
||||
|
||||
|
||||
int GetInt(string sql, object pars);
|
||||
int GetInt(string sql, params SugarParameter[] parameters);
|
||||
int GetInt(string sql, List<SugarParameter> parameters);
|
||||
long GetLong(string sql, object pars);
|
||||
|
||||
Task<int> GetIntAsync(string sql, object pars);
|
||||
Task<int> GetIntAsync(string sql, params SugarParameter[] parameters);
|
||||
Task<int> GetIntAsync(string sql, List<SugarParameter> parameters);
|
||||
|
||||
|
||||
long GetLong(string sql, object pars=null);
|
||||
|
||||
Task<long> GetLongAsync(string sql, object pars=null);
|
||||
|
||||
|
||||
Double GetDouble(string sql, object parameters);
|
||||
Double GetDouble(string sql, params SugarParameter[] parameters);
|
||||
Double GetDouble(string sql, List<SugarParameter> parameters);
|
||||
|
||||
|
||||
Task<Double> GetDoubleAsync(string sql, object parameters);
|
||||
Task<Double> GetDoubleAsync(string sql, params SugarParameter[] parameters);
|
||||
Task<Double> GetDoubleAsync(string sql, List<SugarParameter> parameters);
|
||||
|
||||
|
||||
decimal GetDecimal(string sql, object parameters);
|
||||
decimal GetDecimal(string sql, params SugarParameter[] parameters);
|
||||
decimal GetDecimal(string sql, List<SugarParameter> parameters);
|
||||
|
||||
Task<decimal> GetDecimalAsync(string sql, object parameters);
|
||||
Task<decimal> GetDecimalAsync(string sql, params SugarParameter[] parameters);
|
||||
Task<decimal> GetDecimalAsync(string sql, List<SugarParameter> parameters);
|
||||
|
||||
|
||||
DateTime GetDateTime(string sql, object parameters);
|
||||
DateTime GetDateTime(string sql, params SugarParameter[] parameters);
|
||||
DateTime GetDateTime(string sql, List<SugarParameter> parameters);
|
||||
List<T> SqlQuery<T>(string sql, object parameters = null);
|
||||
|
||||
Task<DateTime> GetDateTimeAsync(string sql, object parameters);
|
||||
Task<DateTime> GetDateTimeAsync(string sql, params SugarParameter[] parameters);
|
||||
Task<DateTime> GetDateTimeAsync(string sql, List<SugarParameter> parameters);
|
||||
|
||||
|
||||
Tuple<List<T>, List<T2>> SqlQuery<T,T2>(string sql, object parameters = null);
|
||||
Tuple<List<T>, List<T2>, List<T3>> SqlQuery<T, T2,T3>(string sql, object parameters = null);
|
||||
Tuple<List<T>, List<T2>, List<T3>,List<T4>> SqlQuery<T,T2,T3,T4>(string sql, object parameters = null);
|
||||
@ -72,14 +134,30 @@ namespace SqlSugar
|
||||
Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>, List<T6>> SqlQuery<T, T2, T3, T4, T5,T6>(string sql, object parameters = null);
|
||||
Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>, List<T6>, List<T7>> SqlQuery<T, T2, T3, T4, T5, T6,T7>(string sql, object parameters = null);
|
||||
|
||||
Task<Tuple<List<T>, List<T2>>> SqlQueryAsync<T, T2>(string sql, object parameters = null);
|
||||
Task<Tuple<List<T>, List<T2>, List<T3>>> SqlQueryAsync<T, T2, T3>(string sql, object parameters = null);
|
||||
Task<Tuple<List<T>, List<T2>, List<T3>, List<T4>>> SqlQueryAsync<T, T2, T3, T4>(string sql, object parameters = null);
|
||||
Task<Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>>> SqlQueryAsync<T, T2, T3, T4, T5>(string sql, object parameters = null);
|
||||
Task<Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>, List<T6>>> SqlQueryAsync<T, T2, T3, T4, T5, T6>(string sql, object parameters = null);
|
||||
Task<Tuple<List<T>, List<T2>, List<T3>, List<T4>, List<T5>, List<T6>, List<T7>>> SqlQueryAsync<T, T2, T3, T4, T5, T6, T7>(string sql, object parameters = null);
|
||||
|
||||
List<T> SqlQuery<T>(string sql, object parameters = null);
|
||||
List<T> SqlQuery<T>(string sql, params SugarParameter[] parameters);
|
||||
List<T> SqlQuery<T>(string sql, List<SugarParameter> parameters);
|
||||
|
||||
Task<List<T>> SqlQueryAsync<T>(string sql, object parameters = null);
|
||||
Task<List<T>> SqlQueryAsync<T>(string sql, List<SugarParameter> parameters);
|
||||
Task<List<T>> SqlQueryAsync<T>(string sql, params SugarParameter[] parameters);
|
||||
|
||||
T SqlQuerySingle<T>(string sql, object whereObj = null);
|
||||
T SqlQuerySingle<T>(string sql, params SugarParameter[] parameters);
|
||||
T SqlQuerySingle<T>(string sql, List<SugarParameter> parameters);
|
||||
dynamic SqlQueryDynamic(string sql, object whereObj = null);
|
||||
dynamic SqlQueryDynamic(string sql, params SugarParameter[] parameters);
|
||||
dynamic SqlQueryDynamic(string sql, List<SugarParameter> parameters);
|
||||
|
||||
Task<T> SqlQuerySingleAsync<T>(string sql, object whereObj = null);
|
||||
Task<T> SqlQuerySingleAsync<T>(string sql, params SugarParameter[] parameters);
|
||||
Task<T> SqlQuerySingleAsync<T>(string sql, List<SugarParameter> parameters);
|
||||
|
||||
|
||||
void Dispose();
|
||||
void Close();
|
||||
void Open();
|
||||
@ -96,9 +174,21 @@ namespace SqlSugar
|
||||
DbResult<T> UseTran<T>(Func<T> action, Action<Exception> errorCallBack = null);
|
||||
Task<DbResult<bool>> UseTranAsync(Action action, Action<Exception> errorCallBack = null);
|
||||
Task<DbResult<T>> UseTranAsync<T>(Func<T> action, Action<Exception> errorCallBack = null);
|
||||
|
||||
void UseStoredProcedure(Action action);
|
||||
T UseStoredProcedure<T>(Func<T> action);
|
||||
IAdo UseStoredProcedure();
|
||||
|
||||
|
||||
|
||||
#region Obsolete
|
||||
[Obsolete("Use db.ado.UseStoredProcedure().MethodName()")]
|
||||
void UseStoredProcedure(Action action);
|
||||
[Obsolete("Use db.ado.UseStoredProcedure().MethodName()")]
|
||||
T UseStoredProcedure<T>(Func<T> action);
|
||||
[Obsolete("Use SqlQuery<dynamic>(sql)")]
|
||||
dynamic SqlQueryDynamic(string sql, object whereObj = null);
|
||||
[Obsolete("Use SqlQuery<dynamic>(sql)")]
|
||||
dynamic SqlQueryDynamic(string sql, params SugarParameter[] parameters);
|
||||
[Obsolete("Use SqlQuery<dynamic>(sql)")]
|
||||
dynamic SqlQueryDynamic(string sql, List<SugarParameter> parameters);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,13 @@ namespace SqlSugar
|
||||
SqlSugarProvider Context { get; set; }
|
||||
ExpandoObject DataReaderToExpandoObject(IDataReader reader);
|
||||
List<ExpandoObject> DataReaderToExpandoObjectList(IDataReader reader);
|
||||
Task<List<ExpandoObject>> DataReaderToExpandoObjectListAsync(IDataReader dataReader);
|
||||
List<ExpandoObject> DataReaderToExpandoObjectListNoUsing(IDataReader reader);
|
||||
Task<List<ExpandoObject>> DataReaderToExpandoObjectListAsyncNoUsing(IDataReader dataReader);
|
||||
List<T> DataReaderToList<T>(IDataReader reader);
|
||||
List<T> DataReaderToListNoUsing<T>(IDataReader reader);
|
||||
Task<List<T>> DataReaderToListAsync<T>(IDataReader dataReader);
|
||||
Task<List<T>> DataReaderToListAsyncNoUsing<T>(IDataReader dataReader);
|
||||
string SerializeObject(object value);
|
||||
string SerializeObject(object value, Type type);
|
||||
T DeserializeObject<T>(string value);
|
||||
@ -27,6 +33,5 @@ namespace SqlSugar
|
||||
void RemoveCacheAll<T>();
|
||||
void RemoveCache<T>(string key);
|
||||
void PageEach<T>(IEnumerable<T> pageItems, int pageSize, Action<List<T>> action);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SqlSugar
|
||||
{
|
||||
public partial interface IDbBind
|
||||
@ -21,6 +23,9 @@ namespace SqlSugar
|
||||
string GetCsharpTypeName(string dbTypeName);
|
||||
List<KeyValuePair<string, CSharpDataType>> MappingTypes { get; }
|
||||
List<T> DataReaderToList<T>(Type type, IDataReader reader);
|
||||
Task<List<T>> DataReaderToListAsync<T>(Type entityType, IDataReader dataReader);
|
||||
List<T> DataReaderToListNoUsing<T>(Type type, IDataReader reader);
|
||||
Task<List<T>> DataReaderToListNoUsingAsync<T>(Type type, IDataReader reader);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ namespace SqlSugar
|
||||
{
|
||||
public partial interface ISugarQueryable<T>
|
||||
{
|
||||
ISqlSugarClient Context { get; set; }
|
||||
SqlSugarProvider Context { get; set; }
|
||||
ISqlBuilder SqlBuilder { get; set; }
|
||||
QueryBuilder QueryBuilder { get; set; }
|
||||
ISugarQueryable<T> Clone();
|
||||
@ -129,7 +129,7 @@ namespace SqlSugar
|
||||
string ToJsonPage(int pageIndex, int pageSize);
|
||||
Task<string> ToJsonPageAsync(int pageIndex, int pageSize);
|
||||
string ToJsonPage(int pageIndex, int pageSize, ref int totalNumber);
|
||||
Task<string> ToJsonPageAsync(int pageIndex, int pageSize,ref int totalNumber);
|
||||
Task<string> ToJsonPageAsync(int pageIndex, int pageSize, RefAsync<int> totalNumber);
|
||||
KeyValuePair<string, List<SugarParameter>> ToSql();
|
||||
|
||||
|
||||
@ -139,13 +139,13 @@ namespace SqlSugar
|
||||
Task<DataTable> ToDataTablePageAsync(int pageIndex, int pageSize);
|
||||
DataTable ToDataTablePage(int pageIndex, int pageSize, ref int totalNumber);
|
||||
DataTable ToDataTablePage(int pageIndex, int pageSize, ref int totalNumber,ref int totalPage);
|
||||
Task<DataTable> ToDataTablePageAsync(int pageIndex, int pageSize,ref int totalNumber);
|
||||
Task<DataTable> ToDataTablePageAsync(int pageIndex, int pageSize, RefAsync<int> totalNumber);
|
||||
|
||||
List<T> ToPageList(int pageIndex, int pageSize);
|
||||
Task<List<T>> ToPageListAsync(int pageIndex, int pageSize);
|
||||
List<T> ToPageList(int pageIndex, int pageSize, ref int totalNumber);
|
||||
List<T> ToPageList(int pageIndex, int pageSize, ref int totalNumber,ref int totalPage);
|
||||
Task<List<T>> ToPageListAsync(int pageIndex, int pageSize,ref int totalNumber);
|
||||
Task<List<T>> ToPageListAsync(int pageIndex, int pageSize, RefAsync<int> totalNumber);
|
||||
ISugarQueryable<T> WithCache(int cacheDurationInSeconds = int.MaxValue);
|
||||
ISugarQueryable<T> WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue);
|
||||
string ToClassString(string className);
|
||||
|
@ -23,7 +23,7 @@ namespace SqlSugar
|
||||
IAdo Ado { get; }
|
||||
AopProvider Aop { get; }
|
||||
ICodeFirst CodeFirst { get; }
|
||||
ISqlSugarClient Context { get; set; }
|
||||
|
||||
|
||||
IDbFirst DbFirst { get; }
|
||||
IDbMaintenance DbMaintenance { get; }
|
||||
|
@ -12,7 +12,7 @@ namespace SqlSugar
|
||||
public partial class SqlSugarClient : ISqlSugarClient, ITenant
|
||||
{
|
||||
#region Gobal Property
|
||||
private ISqlSugarClient _Context = null;
|
||||
private SqlSugarProvider _Context = null;
|
||||
private string _ThreadId;
|
||||
private ConnectionConfig _CurrentConnectionConfig;
|
||||
private List<SugarTenant> _AllClients;
|
||||
@ -45,7 +45,7 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Global variable
|
||||
public ISqlSugarClient Context { get => GetContext(); set => _Context = value; }
|
||||
public SqlSugarProvider Context { get => GetContext(); }
|
||||
public bool IsSystemTablesConfig => this.Context.IsSystemTablesConfig;
|
||||
public ConnectionConfig CurrentConnectionConfig { get => _CurrentConnectionConfig; set => _CurrentConnectionConfig = value; }
|
||||
public Guid ContextID { get => this.Context.ContextID; set => this.Context.ContextID = value; }
|
||||
@ -669,33 +669,43 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Helper
|
||||
private ISqlSugarClient GetContext()
|
||||
{
|
||||
if (CurrentConnectionConfig.IsShardSameThread)
|
||||
{
|
||||
ISqlSugarClient result = _Context;
|
||||
if (CallContext.ContextList.Value.IsNullOrEmpty())
|
||||
private SqlSugarProvider GetContext()
|
||||
{
|
||||
if (IsSameThreadAndShard())
|
||||
return SameThreadAndShard();
|
||||
else if (IsNoSameThreadAndShard())
|
||||
return NoSameThreadAndShard();
|
||||
else if (IsSynchronization())
|
||||
return Synchronization();
|
||||
else
|
||||
return NoSameThread();
|
||||
}
|
||||
|
||||
CallContext.ContextList.Value = new List<ISqlSugarClient>();
|
||||
CallContext.ContextList.Value.Add(_Context);
|
||||
private SqlSugarProvider NoSameThread()
|
||||
{
|
||||
if (CallContext.ContextList.Value == null)
|
||||
{
|
||||
var context = CopyClient();
|
||||
AddCallContext(context);
|
||||
return context;
|
||||
}
|
||||
else
|
||||
{
|
||||
ISqlSugarClient cacheContext = GetCallContext();
|
||||
if (cacheContext != null)
|
||||
var result = GetCallContext();
|
||||
if (result == null)
|
||||
{
|
||||
result = cacheContext;
|
||||
var copy = CopyClient();
|
||||
AddCallContext(copy);
|
||||
return copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = CopyClient();
|
||||
CallContext.ContextList.Value.Add(result);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
else if (_ThreadId == Thread.CurrentThread.ManagedThreadId.ToString())
|
||||
}
|
||||
}
|
||||
|
||||
private SqlSugarProvider Synchronization()
|
||||
{
|
||||
_Context.MappingColumns = _MappingColumns;
|
||||
_Context.MappingTables = _MappingTables;
|
||||
@ -703,28 +713,73 @@ namespace SqlSugar
|
||||
_Context.IgnoreInsertColumns = _IgnoreInsertColumns;
|
||||
return _Context;
|
||||
}
|
||||
else
|
||||
|
||||
private SqlSugarProvider NoSameThreadAndShard()
|
||||
{
|
||||
if (CallContext.ContextList.Value == null)
|
||||
if (CallContext.ContextList.Value.IsNullOrEmpty())
|
||||
{
|
||||
CallContext.ContextList.Value = new List<ISqlSugarClient>();
|
||||
}
|
||||
if (CallContext.ContextList.Value.IsNullOrEmpty() || GetCallContext() == null)
|
||||
{
|
||||
var context = CopyClient();
|
||||
CallContext.ContextList.Value.Add(context);
|
||||
return context;
|
||||
var copy = CopyClient();
|
||||
AddCallContext(copy);
|
||||
return copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetCallContext();
|
||||
var result = GetCallContext();
|
||||
if (result == null)
|
||||
{
|
||||
var copy = CopyClient();
|
||||
AddCallContext(copy);
|
||||
return copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private SqlSugarClient CopyClient()
|
||||
private SqlSugarProvider SameThreadAndShard()
|
||||
{
|
||||
var result = new SqlSugarClient(this.CurrentConnectionConfig);
|
||||
if (CallContext.ContextList.Value.IsNullOrEmpty())
|
||||
{
|
||||
AddCallContext(_Context);
|
||||
return _Context;
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = GetCallContext();
|
||||
if (result == null)
|
||||
{
|
||||
var copy = CopyClient();
|
||||
AddCallContext(copy);
|
||||
return copy;
|
||||
}
|
||||
else
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private bool IsSynchronization()
|
||||
{
|
||||
return _ThreadId == Thread.CurrentThread.ManagedThreadId.ToString();
|
||||
}
|
||||
|
||||
private bool IsNoSameThreadAndShard()
|
||||
{
|
||||
return CurrentConnectionConfig.IsShardSameThread && _ThreadId != Thread.CurrentThread.ManagedThreadId.ToString();
|
||||
}
|
||||
|
||||
private bool IsSameThreadAndShard()
|
||||
{
|
||||
return CurrentConnectionConfig.IsShardSameThread && _ThreadId == Thread.CurrentThread.ManagedThreadId.ToString();
|
||||
}
|
||||
|
||||
private SqlSugarProvider CopyClient()
|
||||
{
|
||||
var result = new SqlSugarProvider(this.CurrentConnectionConfig);
|
||||
result.MappingColumns = _MappingColumns;
|
||||
result.MappingTables = _MappingTables;
|
||||
result.IgnoreColumns = _IgnoreColumns;
|
||||
@ -732,13 +787,19 @@ namespace SqlSugar
|
||||
|
||||
return result;
|
||||
}
|
||||
private void AddCallContext(SqlSugarProvider context)
|
||||
{
|
||||
CallContext.ContextList.Value = new List<SqlSugarProvider>();
|
||||
CallContext.ContextList.Value.Add(context);
|
||||
}
|
||||
|
||||
private ISqlSugarClient GetCallContext()
|
||||
private SqlSugarProvider GetCallContext()
|
||||
{
|
||||
return CallContext.ContextList.Value.FirstOrDefault(it =>
|
||||
it.CurrentConnectionConfig.DbType == _Context.CurrentConnectionConfig.DbType &&
|
||||
it.CurrentConnectionConfig.ConnectionString == _Context.CurrentConnectionConfig.ConnectionString &&
|
||||
it.CurrentConnectionConfig.InitKeyType==_Context.CurrentConnectionConfig.InitKeyType
|
||||
it.CurrentConnectionConfig.InitKeyType == _Context.CurrentConnectionConfig.InitKeyType &&
|
||||
it.CurrentConnectionConfig.IsAutoCloseConnection == _Context.CurrentConnectionConfig.IsAutoCloseConnection
|
||||
);
|
||||
}
|
||||
|
||||
@ -789,19 +850,11 @@ namespace SqlSugar
|
||||
{
|
||||
if (Tenant.Context == null)
|
||||
{
|
||||
Tenant.Context = new SqlSugarClient(Tenant.ConnectionConfig);
|
||||
Tenant.Context = new SqlSugarProvider(Tenant.ConnectionConfig);
|
||||
}
|
||||
_Context = Tenant.Context;
|
||||
this.CurrentConnectionConfig = Tenant.ConnectionConfig;
|
||||
}
|
||||
//private void TaskStart<Type>(Task<Type> result)
|
||||
//{
|
||||
// if (this.Context.CurrentConnectionConfig.IsShardSameThread)
|
||||
// {
|
||||
// Check.Exception(true, "IsShardSameThread=true can't be used async method");
|
||||
// }
|
||||
// result.Start();
|
||||
//}
|
||||
#endregion
|
||||
|
||||
#region Obsolete
|
||||
|
@ -2,7 +2,7 @@
|
||||
<package >
|
||||
<metadata>
|
||||
<id>sqlSugarCore</id>
|
||||
<version>4.9.9.10</version>
|
||||
<version>5.0</version>
|
||||
<authors>sunkaixuan</authors>
|
||||
<owners>Landa</owners>
|
||||
<licenseUrl>http://www.apache.org/licenses/LICENSE-2.0.html</licenseUrl>
|
||||
|
@ -10,6 +10,6 @@ namespace SqlSugar
|
||||
{
|
||||
internal class CallContext
|
||||
{
|
||||
public static ThreadLocal<List<ISqlSugarClient>> ContextList = new ThreadLocal<List<ISqlSugarClient>>();
|
||||
public static ThreadLocal<List<SqlSugarProvider>> ContextList = new ThreadLocal<List<SqlSugarProvider>>();
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user