mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 01:58:13 +08:00
-
This commit is contained in:
@@ -10,7 +10,7 @@ namespace SqlSugar
|
||||
protected List<T> GetEntityList<T>(SqlSugarClient context, IDataReader dataReader, string fields)
|
||||
{
|
||||
Type type = typeof(T);
|
||||
string key = "DataReaderToList." + fields + context.CurrentConnectionConfig.DbType + type.FullName;
|
||||
string key = "DataReaderToList." + fields+ dataReader.FieldCount+ context.CurrentConnectionConfig.DbType + type.FullName;
|
||||
IDataReaderEntityBuilder<T> entytyList = context.Utilities.GetReflectionInoCacheInstance().GetOrCreate(key, () =>
|
||||
{
|
||||
var cacheResult = new IDataReaderEntityBuilder<T>(context, dataReader).CreateBuilder(type);
|
||||
|
@@ -74,19 +74,19 @@ namespace SqlSugar
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, T8>();
|
||||
InitMppingInfo<T9>();
|
||||
}
|
||||
protected void InitMppingInfo<T, T2, T3, T4, T5, T6, T7, T8,T9,T10>()
|
||||
protected void InitMppingInfo<T, T2, T3, T4, T5, T6, T7, T8, T9, T10>()
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T7,T8,T9>();
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, T8, T9>();
|
||||
InitMppingInfo<T10>();
|
||||
}
|
||||
protected void InitMppingInfo<T, T2, T3, T4, T5, T6, T7, T8, T9, T10,T11>()
|
||||
protected void InitMppingInfo<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>()
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, T8, T9,T10>();
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, T8, T9, T10>();
|
||||
InitMppingInfo<T11>();
|
||||
}
|
||||
protected void InitMppingInfo<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11,T12>()
|
||||
protected void InitMppingInfo<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12>()
|
||||
{
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, T8, T9, T10,T11>();
|
||||
InitMppingInfo<T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11>();
|
||||
InitMppingInfo<T12>();
|
||||
}
|
||||
#endregion
|
||||
@@ -206,10 +206,11 @@ namespace SqlSugar
|
||||
{
|
||||
this.CreateQueryable<T>(queryable);
|
||||
string shortName = string.Empty;
|
||||
List<SugarParameter> paramters =new List<SugarParameter>();
|
||||
queryable.SqlBuilder.QueryBuilder.JoinQueryInfos = this.GetJoinInfos(queryable.SqlBuilder,joinExpression, ref paramters, ref shortName, types);
|
||||
List<SugarParameter> paramters = new List<SugarParameter>();
|
||||
queryable.SqlBuilder.QueryBuilder.JoinQueryInfos = this.GetJoinInfos(queryable.SqlBuilder, joinExpression, ref paramters, ref shortName, types);
|
||||
queryable.SqlBuilder.QueryBuilder.TableShortName = shortName;
|
||||
if (paramters != null) {
|
||||
if (paramters != null)
|
||||
{
|
||||
queryable.SqlBuilder.QueryBuilder.Parameters.AddRange(paramters);
|
||||
}
|
||||
}
|
||||
@@ -217,13 +218,13 @@ namespace SqlSugar
|
||||
{
|
||||
this.CreateQueryable<T>(queryable);
|
||||
string shortName = string.Empty;
|
||||
queryable.SqlBuilder.QueryBuilder.EasyJoinInfos = this.GetEasyJoinInfo(joinExpression, ref shortName,queryable.SqlBuilder,types);
|
||||
queryable.SqlBuilder.QueryBuilder.EasyJoinInfos = this.GetEasyJoinInfo(joinExpression, ref shortName, queryable.SqlBuilder, types);
|
||||
queryable.SqlBuilder.QueryBuilder.TableShortName = shortName;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Private methods
|
||||
protected List<JoinQueryInfo> GetJoinInfos(ISqlBuilder sqlBuilder,Expression joinExpression,ref List<SugarParameter> parameters, ref string shortName, params Type[] entityTypeArray)
|
||||
protected List<JoinQueryInfo> GetJoinInfos(ISqlBuilder sqlBuilder, Expression joinExpression, ref List<SugarParameter> parameters, ref string shortName, params Type[] entityTypeArray)
|
||||
{
|
||||
List<JoinQueryInfo> result = new List<JoinQueryInfo>();
|
||||
var lambdaParameters = ((LambdaExpression)joinExpression).Parameters.ToList();
|
||||
@@ -232,7 +233,7 @@ namespace SqlSugar
|
||||
expressionContext.MappingTables = this.Context.MappingTables;
|
||||
expressionContext.Resolve(joinExpression, ResolveExpressType.Join);
|
||||
int i = 0;
|
||||
var joinArray = expressionContext.Result.GetResultArray();
|
||||
var joinArray = MergeJoinArray(expressionContext.Result.GetResultArray());
|
||||
parameters = expressionContext.Parameters;
|
||||
foreach (var entityType in entityTypeArray)
|
||||
{
|
||||
@@ -265,7 +266,38 @@ namespace SqlSugar
|
||||
expressionContext.Clear();
|
||||
return result;
|
||||
}
|
||||
protected Dictionary<string,string> GetEasyJoinInfo(Expression joinExpression, ref string shortName, ISqlBuilder builder, params Type[] entityTypeArray)
|
||||
|
||||
private string[] MergeJoinArray(string[] joinArray)
|
||||
{
|
||||
List<string> result = new List<string>();
|
||||
string joinValue = null;
|
||||
int i = 0;
|
||||
foreach (var item in joinArray)
|
||||
{
|
||||
++i;
|
||||
var isLast = joinArray.Length == i;
|
||||
var isJoinType = item.IsIn(JoinType.Inner.ToString(), JoinType.Left.ToString(), JoinType.Right.ToString());
|
||||
if (isJoinType)
|
||||
{
|
||||
if (joinValue != null)
|
||||
result.Add(joinValue);
|
||||
joinValue = null;
|
||||
result.Add(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
isJoinType = false;
|
||||
joinValue += joinValue==null?item:(","+item);
|
||||
}
|
||||
if (isLast)
|
||||
{
|
||||
result.Add(joinValue);
|
||||
}
|
||||
}
|
||||
return result.ToArray(); ;
|
||||
}
|
||||
|
||||
protected Dictionary<string, string> GetEasyJoinInfo(Expression joinExpression, ref string shortName, ISqlBuilder builder, params Type[] entityTypeArray)
|
||||
{
|
||||
Dictionary<string, string> result = new Dictionary<string, string>();
|
||||
var lambdaParameters = ((LambdaExpression)joinExpression).Parameters.ToList();
|
||||
@@ -273,7 +305,7 @@ namespace SqlSugar
|
||||
var index = 1;
|
||||
foreach (var item in entityTypeArray)
|
||||
{
|
||||
result.Add(UtilConstants.Space +lambdaParameters[index].Name, item.Name);
|
||||
result.Add(UtilConstants.Space + lambdaParameters[index].Name, item.Name);
|
||||
++index;
|
||||
}
|
||||
return result;
|
||||
|
Reference in New Issue
Block a user