using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Text.RegularExpressions; using System.Reflection; using System.Dynamic; using System.Threading.Tasks; namespace SqlSugar { #region T11 public partial class QueryableProvider : QueryableProvider, ISugarQueryable { public new ISugarQueryable Hints(string hints) { this.QueryBuilder.Hints = hints; return this; } public new ISugarQueryable OrderByPropertyNameIF(bool isOrderBy, string orderPropertyName, OrderByType? orderByType = null) { if (isOrderBy) { return this.OrderByPropertyName(orderPropertyName, orderByType); } return this; } public new ISugarQueryable OrderByPropertyName(string orderPropertyName, OrderByType? orderByType = null) { base.OrderByPropertyName(orderPropertyName, orderByType); return this; } public virtual ISugarQueryable SelectMergeTable(Expression> expression) { return this.Select(expression).MergeTable(); } public ISugarQueryable LeftJoinIF(bool isLeftJoin, Expression> joinExpression) { var result = LeftJoin(joinExpression); if (isLeftJoin == false) { result.QueryBuilder.JoinQueryInfos.Remove(result.QueryBuilder.JoinQueryInfos.Last()); } return result; } public ISugarQueryable InnerJoinIF(bool isJoin, Expression> joinExpression) { var result = InnerJoin(joinExpression); if (isJoin == false) { result.QueryBuilder.JoinQueryInfos.Remove(result.QueryBuilder.JoinQueryInfos.Last()); } return result; } public ISugarQueryable LeftJoin(ISugarQueryable joinQueryable, Expression> joinExpression) { this.Context.InitMappingInfo(); var result = InstanceFactory.GetQueryable(this.Context.CurrentConnectionConfig); result.SqlBuilder = this.SqlBuilder; result.Context = this.Context; var joinInfo = GetJoinInfo(joinExpression, JoinType.Left); var sqlObject = joinQueryable.ToSql(); string sql = sqlObject.Key; this.QueryBuilder.LambdaExpressions.ParameterIndex += 100; UtilMethods.RepairReplicationParameters(ref sql, sqlObject.Value.ToArray(), this.QueryBuilder.LambdaExpressions.ParameterIndex, ""); joinInfo.TableName = "(" + sql + ")"; this.QueryBuilder.Parameters.AddRange(sqlObject.Value); result.QueryBuilder.JoinQueryInfos.Add(joinInfo); result.QueryBuilder.LambdaExpressions.ParameterIndex = this.QueryBuilder.LambdaExpressions.ParameterIndex; return result; } public ISugarQueryable InnerJoin(ISugarQueryable joinQueryable, Expression> joinExpression) { this.Context.InitMappingInfo(); var result = InstanceFactory.GetQueryable(this.Context.CurrentConnectionConfig); result.SqlBuilder = this.SqlBuilder; result.Context = this.Context; var joinInfo = GetJoinInfo(joinExpression, JoinType.Inner); var sqlObject = joinQueryable.ToSql(); string sql = sqlObject.Key; this.QueryBuilder.LambdaExpressions.ParameterIndex += 100; UtilMethods.RepairReplicationParameters(ref sql, sqlObject.Value.ToArray(), this.QueryBuilder.LambdaExpressions.ParameterIndex, ""); joinInfo.TableName = "(" + sql + ")"; this.QueryBuilder.Parameters.AddRange(sqlObject.Value); result.QueryBuilder.JoinQueryInfos.Add(joinInfo); result.QueryBuilder.LambdaExpressions.ParameterIndex = this.QueryBuilder.LambdaExpressions.ParameterIndex; return result; } public ISugarQueryable RightJoin(ISugarQueryable joinQueryable, Expression> joinExpression) { this.Context.InitMappingInfo(); var result = InstanceFactory.GetQueryable(this.Context.CurrentConnectionConfig); result.SqlBuilder = this.SqlBuilder; result.Context = this.Context; var joinInfo = GetJoinInfo(joinExpression, JoinType.Right); var sqlObject = joinQueryable.ToSql(); string sql = sqlObject.Key; this.QueryBuilder.LambdaExpressions.ParameterIndex += 100; UtilMethods.RepairReplicationParameters(ref sql, sqlObject.Value.ToArray(), this.QueryBuilder.LambdaExpressions.ParameterIndex, ""); joinInfo.TableName = "(" + sql + ")"; this.QueryBuilder.Parameters.AddRange(sqlObject.Value); result.QueryBuilder.JoinQueryInfos.Add(joinInfo); result.QueryBuilder.LambdaExpressions.ParameterIndex = this.QueryBuilder.LambdaExpressions.ParameterIndex; return result; } public ISugarQueryable LeftJoin(Expression> joinExpression) { this.Context.InitMappingInfo(); var result = InstanceFactory.GetQueryable(this.Context.CurrentConnectionConfig); result.SqlBuilder = this.SqlBuilder; result.Context = this.Context; result.QueryBuilder.JoinQueryInfos.Add(GetJoinInfo(joinExpression, JoinType.Left)); return result; } public ISugarQueryable FullJoin(Expression> joinExpression) { this.Context.InitMappingInfo(); var result = InstanceFactory.GetQueryable(this.Context.CurrentConnectionConfig); result.SqlBuilder = this.SqlBuilder; result.Context = this.Context; result.QueryBuilder.JoinQueryInfos.Add(GetJoinInfo(joinExpression, JoinType.Full)); return result; } public ISugarQueryable RightJoin(Expression> joinExpression) { this.Context.InitMappingInfo(); var result = InstanceFactory.GetQueryable(this.Context.CurrentConnectionConfig); result.SqlBuilder = this.SqlBuilder; result.Context = this.Context; result.QueryBuilder.JoinQueryInfos.Add(GetJoinInfo(joinExpression, JoinType.Right)); return result; } public ISugarQueryable InnerJoin(Expression> joinExpression) { this.Context.InitMappingInfo(); var result = InstanceFactory.GetQueryable(this.Context.CurrentConnectionConfig); result.SqlBuilder = this.SqlBuilder; result.Context = this.Context; result.QueryBuilder.JoinQueryInfos.Add(GetJoinInfo(joinExpression, JoinType.Inner)); return result; } public ISugarQueryable LeftJoin(Expression> joinExpression, string tableName) { var result = LeftJoin(joinExpression); result.QueryBuilder.JoinQueryInfos.Last().TableName = tableName; return result; } public ISugarQueryable FullJoin(Expression> joinExpression, string tableName) { var result = FullJoin(joinExpression); result.QueryBuilder.JoinQueryInfos.Last().TableName = tableName; return result; } public ISugarQueryable InnerJoin(Expression> joinExpression, string tableName) { var result = InnerJoin(joinExpression); result.QueryBuilder.JoinQueryInfos.Last().TableName = tableName; return result; } public ISugarQueryable RightJoin(Expression> joinExpression, string tableName) { var result = RightJoin(joinExpression); result.QueryBuilder.JoinQueryInfos.Last().TableName = tableName; return result; } #region Where public new ISugarQueryable Where(string expShortName, FormattableString expressionString) { var exp = DynamicCoreHelper.GetWhere(expShortName, expressionString); _Where(exp); return this; } public new ISugarQueryable Where(Expression> expression) { _Where(expression); return this; } public ISugarQueryable Where(Expression> expression) { _Where(expression); return this; } public ISugarQueryable Where(Expression> expression) { _Where(expression); return this; } public ISugarQueryable Where(Expression> expression) { _Where(expression); return this; } public ISugarQueryable Where(Expression> expression) { _Where(expression); return this; } public ISugarQueryable Where(Expression> expression) { _Where(expression); return this; } public ISugarQueryable Where(Expression> expression) { _Where(expression); return this; } public ISugarQueryable Where(Expression> expression) { _Where(expression); return this; } public ISugarQueryable Where(Expression> expression) { _Where(expression); return this; } public ISugarQueryable Where(Expression> expression) { _Where(expression); return this; } public ISugarQueryable Where(Expression> expression) { _Where(expression); return this; } public new ISugarQueryable WhereIF(bool isWhere, Expression> expression) { if (isWhere) _Where(expression); return this; } public new ISugarQueryable Where(List conditionalModels) { base.Where(conditionalModels); return this; } public new ISugarQueryable Where(List conditionalModels, bool isWrap) { base.Where(conditionalModels, isWrap); return this; } public ISugarQueryable WhereIF(bool isWhere, Expression> expression) { if (isWhere) _Where(expression); return this; } public ISugarQueryable WhereIF(bool isWhere, Expression> expression) { if (isWhere) _Where(expression); return this; } public ISugarQueryable WhereIF(bool isWhere, Expression> expression) { if (isWhere) _Where(expression); return this; } public ISugarQueryable WhereIF(bool isWhere, Expression> expression) { if (isWhere) _Where(expression); return this; } public ISugarQueryable WhereIF(bool isWhere, Expression> expression) { if (isWhere) _Where(expression); return this; } public ISugarQueryable WhereIF(bool isWhere, Expression> expression) { if (isWhere) _Where(expression); return this; } public ISugarQueryable WhereIF(bool isWhere, Expression> expression) { if (isWhere) _Where(expression); return this; } public ISugarQueryable WhereIF(bool isWhere, Expression> expression) { if (isWhere) _Where(expression); return this; } public ISugarQueryable WhereIF(bool isWhere, Expression> expression) { if (isWhere) _Where(expression); return this; } public ISugarQueryable WhereIF(bool isWhere, Expression> expression) { if (isWhere) _Where(expression); return this; } public new ISugarQueryable Where(string whereString, object whereObj) { Where(whereString, whereObj); return this; } public new ISugarQueryable WhereIF(bool isWhere, string whereString, object whereObj) { if (!isWhere) return this; this.Where(whereString, whereObj); return this; } #endregion #region Select public ISugarQueryable Select(Expression> expression, bool isAutoFill) { var clone = this.Select(expression).Clone(); var sql = clone.QueryBuilder.GetSelectValue; if (this.QueryBuilder.IsSingle() || string.IsNullOrEmpty(sql) || sql.Trim() == "*") { sql = " "; } this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters; this.QueryBuilder.SubToListParameters = clone.QueryBuilder.SubToListParameters; this.QueryBuilder.LambdaExpressions.ParameterIndex = clone.QueryBuilder.LambdaExpressions.ParameterIndex; var parameters = (expression as LambdaExpression).Parameters; var columnsResult = this.Context.EntityMaintenance.GetEntityInfo().Columns; sql = AppendSelect(sql, parameters, columnsResult, 0); sql = AppendSelect(sql, parameters, columnsResult, 1); sql = AppendSelect(sql, parameters, columnsResult, 2); sql = AppendSelect(sql, parameters, columnsResult, 3); sql = AppendSelect(sql, parameters, columnsResult, 4); sql = AppendSelect(sql, parameters, columnsResult, 5); sql = AppendSelect(sql, parameters, columnsResult, 6); sql = AppendSelect(sql, parameters, columnsResult, 7); sql = AppendSelect(sql, parameters, columnsResult, 8); sql = AppendSelect(sql, parameters, columnsResult, 9); sql = AppendSelect(sql, parameters, columnsResult, 10); if (sql.Trim().First() == ',') { sql = sql.TrimStart(' ').TrimStart(','); } return this.Select(sql); } public ISugarQueryable Select(Expression> expression) { return _Select(expression); } public ISugarQueryable Select(Expression> expression) { return _Select(expression); } public ISugarQueryable Select(Expression> expression) { return _Select(expression); } public ISugarQueryable Select(Expression> expression) { return _Select(expression); } public ISugarQueryable Select(Expression> expression) { return _Select(expression); } public ISugarQueryable Select(Expression> expression) { return _Select(expression); } public ISugarQueryable Select(Expression> expression) { return _Select(expression); } public ISugarQueryable Select(Expression> expression) { return _Select(expression); } public ISugarQueryable Select(Expression> expression) { return _Select(expression); } public ISugarQueryable Select(Expression> expression) { return _Select(expression); } #endregion #region OrderBy public new ISugarQueryable OrderBy(List models) { base.OrderBy(models); return this; } public new ISugarQueryable OrderBy(string orderByFields) { base.OrderBy(orderByFields); return this; } public new ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc) { _OrderBy(expression, type); return this; } public ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc) { _OrderBy(expression, type); return this; } public ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc) { _OrderBy(expression, type); return this; } public ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc) { _OrderBy(expression, type); return this; } public ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc) { _OrderBy(expression, type); return this; } public ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc) { _OrderBy(expression, type); return this; } public ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc) { _OrderBy(expression, type); return this; } public ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc) { _OrderBy(expression, type); return this; } public ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc) { _OrderBy(expression, type); return this; } public ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc) { _OrderBy(expression, type); return this; } public ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc) { _OrderBy(expression, type); return this; } public new ISugarQueryable OrderByIF(bool isOrderBy, string orderByFields) { if (isOrderBy) base.OrderBy(orderByFields); return this; } public new ISugarQueryable OrderByIF(bool isOrderBy, Expression> expression, OrderByType type = OrderByType.Asc) { if (isOrderBy) _OrderBy(expression, type); return this; } public ISugarQueryable OrderByIF(bool isOrderBy, Expression> expression, OrderByType type = OrderByType.Asc) { if (isOrderBy) _OrderBy(expression, type); return this; } public ISugarQueryable OrderByIF(bool isOrderBy, Expression> expression, OrderByType type = OrderByType.Asc) { if (isOrderBy) _OrderBy(expression, type); return this; } public ISugarQueryable OrderByIF(bool isOrderBy, Expression> expression, OrderByType type = OrderByType.Asc) { if (isOrderBy) _OrderBy(expression, type); return this; } public ISugarQueryable OrderByIF(bool isOrderBy, Expression> expression, OrderByType type = OrderByType.Asc) { if (isOrderBy) _OrderBy(expression, type); return this; } public ISugarQueryable OrderByIF(bool isOrderBy, Expression> expression, OrderByType type = OrderByType.Asc) { if (isOrderBy) _OrderBy(expression, type); return this; } public ISugarQueryable OrderByIF(bool isOrderBy, Expression> expression, OrderByType type = OrderByType.Asc) { if (isOrderBy) _OrderBy(expression, type); return this; } public ISugarQueryable OrderByIF(bool isOrderBy, Expression> expression, OrderByType type = OrderByType.Asc) { if (isOrderBy) _OrderBy(expression, type); return this; } public ISugarQueryable OrderByIF(bool isOrderBy, Expression> expression, OrderByType type = OrderByType.Asc) { if (isOrderBy) _OrderBy(expression, type); return this; } public ISugarQueryable OrderByIF(bool isOrderBy, Expression> expression, OrderByType type = OrderByType.Asc) { if (isOrderBy) _OrderBy(expression, type); return this; } public ISugarQueryable OrderByIF(bool isOrderBy, Expression> expression, OrderByType type = OrderByType.Asc) { if (isOrderBy) _OrderBy(expression, type); return this; } #endregion #region GroupBy public new ISugarQueryable GroupBy(Expression> expression) { _GroupBy(expression); return this; } public ISugarQueryable GroupBy(Expression> expression) { _GroupBy(expression); return this; } public ISugarQueryable GroupBy(Expression> expression) { _GroupBy(expression); return this; } public ISugarQueryable GroupBy(Expression> expression) { _GroupBy(expression); return this; } public ISugarQueryable GroupBy(Expression> expression) { _GroupBy(expression); return this; } public ISugarQueryable GroupBy(Expression> expression) { _GroupBy(expression); return this; } public ISugarQueryable GroupBy(Expression> expression) { _GroupBy(expression); return this; } public ISugarQueryable GroupBy(Expression> expression) { _GroupBy(expression); return this; } public ISugarQueryable GroupBy(Expression> expression) { _GroupBy(expression); return this; } public ISugarQueryable GroupBy(Expression> expression) { _GroupBy(expression); return this; } public ISugarQueryable GroupBy(Expression> expression) { _GroupBy(expression); return this; } #endregion #region Aggr public TResult Max(Expression> expression) { return _Max(expression); } public TResult Min(Expression> expression) { return _Min(expression); } public TResult Sum(Expression> expression) { return _Sum(expression); } public TResult Avg(Expression> expression) { return _Avg(expression); } #endregion #region In public new ISugarQueryable In(Expression> expression, params FieldType[] inValues) { var isSingle = QueryBuilder.IsSingle(); var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); var fieldName = lamResult.GetResultString(); In(fieldName, inValues); return this; } public new ISugarQueryable In(Expression> expression, List inValues) { var isSingle = QueryBuilder.IsSingle(); var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); var fieldName = lamResult.GetResultString(); In(fieldName, inValues); return this; } public new ISugarQueryable In(Expression> expression, ISugarQueryable childQueryExpression) { var sqlObj = childQueryExpression.ToSql(); _InQueryable(expression, sqlObj); return this; } #endregion #region Other public new ISugarQueryable Distinct() { QueryBuilder.IsDistinct = true; return this; } public new ISugarQueryable Take(int num) { QueryBuilder.Take = num; return this; } public new ISugarQueryable Clone() { var queryable = this.Context.Queryable((t, t2, t3, t4, t5, T6, t7, t8, t9, t10, t11) => new object[] { }).WithCacheIF(IsCache, CacheTime); base.CopyQueryBuilder(queryable.QueryBuilder); return queryable; } public new ISugarQueryable AS(string tableName) { var entityName = typeof(AsT).Name; _As(tableName, entityName); return this; } public new ISugarQueryable AS(string tableName) { var entityName = typeof(T).Name; _As(tableName, entityName); return this; } public new ISugarQueryable ClearFilter() { this.Filter(null, true); return this; } public new ISugarQueryable Filter(string FilterName, bool isDisabledGobalFilter = false) { _Filter(FilterName, isDisabledGobalFilter); return this; } public new ISugarQueryable ClearFilter(params Type[] types) { base.ClearFilter(types); return this; } public new ISugarQueryable ClearFilter() { this.ClearFilter(typeof(FilterType1)); return this; } public new ISugarQueryable ClearFilter() { this.ClearFilter(typeof(FilterType1), typeof(FilterType2)); return this; } public new ISugarQueryable ClearFilter() { this.ClearFilter(typeof(FilterType1), typeof(FilterType2), typeof(FilterType3)); return this; } public new ISugarQueryable AddParameters(object parameters) { if (parameters != null) QueryBuilder.Parameters.AddRange(Context.Ado.GetParameters(parameters)); return this; } public new ISugarQueryable AddParameters(SugarParameter[] parameters) { if (parameters != null) QueryBuilder.Parameters.AddRange(parameters); return this; } public new ISugarQueryable AddParameters(List parameters) { if (parameters != null) QueryBuilder.Parameters.AddRange(parameters); return this; } public new ISugarQueryable AddJoinInfo(string tableName, string shortName, string joinWhere, JoinType type = JoinType.Left) { QueryBuilder.JoinIndex = +1; QueryBuilder.JoinQueryInfos .Add(new JoinQueryInfo() { JoinIndex = QueryBuilder.JoinIndex, TableName = tableName, ShortName = shortName, JoinType = type, JoinWhere = joinWhere }); return this; } public new ISugarQueryable With(string withString) { base.With(withString); return this; } public new ISugarQueryable WithCache(int cacheDurationInSeconds = int.MaxValue) { cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds); this.IsCache = true; this.CacheTime = cacheDurationInSeconds; return this; } public new ISugarQueryable WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue) { cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds); if (IsCache) { this.IsCache = true; this.CacheTime = cacheDurationInSeconds; } return this; } #endregion } #endregion #region T12 public partial class QueryableProvider : QueryableProvider, ISugarQueryable { public new ISugarQueryable Hints(string hints) { this.QueryBuilder.Hints = hints; return this; } public new ISugarQueryable OrderByPropertyNameIF(bool isOrderBy, string orderPropertyName, OrderByType? orderByType = null) { if (isOrderBy) { return this.OrderByPropertyName(orderPropertyName, orderByType); } return this; } public new ISugarQueryable OrderByPropertyName(string orderPropertyName, OrderByType? orderByType = null) { base.OrderByPropertyName(orderPropertyName, orderByType); return this; } public virtual ISugarQueryable SelectMergeTable(Expression> expression) { return this.Select(expression).MergeTable(); } #region Where public new ISugarQueryable Where(string expShortName, FormattableString expressionString) { var exp = DynamicCoreHelper.GetWhere(expShortName, expressionString); _Where(exp); return this; } public new ISugarQueryable Where(Expression> expression) { _Where(expression); return this; } public ISugarQueryable Where(Expression> expression) { _Where(expression); return this; } public ISugarQueryable Where(Expression> expression) { _Where(expression); return this; } public ISugarQueryable Where(Expression> expression) { _Where(expression); return this; } public ISugarQueryable Where(Expression> expression) { _Where(expression); return this; } public ISugarQueryable Where(Expression> expression) { _Where(expression); return this; } public ISugarQueryable Where(Expression> expression) { _Where(expression); return this; } public ISugarQueryable Where(Expression> expression) { _Where(expression); return this; } public ISugarQueryable Where(Expression> expression) { _Where(expression); return this; } public ISugarQueryable Where(Expression> expression) { _Where(expression); return this; } public ISugarQueryable Where(Expression> expression) { _Where(expression); return this; } public ISugarQueryable Where(Expression> expression) { _Where(expression); return this; } public new ISugarQueryable Where(List conditionalModels) { base.Where(conditionalModels); return this; } public new ISugarQueryable Where(List conditionalModels, bool isWrap) { base.Where(conditionalModels, isWrap); return this; } public new ISugarQueryable WhereIF(bool isWhere, Expression> expression) { if (isWhere) _Where(expression); return this; } public ISugarQueryable WhereIF(bool isWhere, Expression> expression) { if (isWhere) _Where(expression); return this; } public ISugarQueryable WhereIF(bool isWhere, Expression> expression) { if (isWhere) _Where(expression); return this; } public ISugarQueryable WhereIF(bool isWhere, Expression> expression) { if (isWhere) _Where(expression); return this; } public ISugarQueryable WhereIF(bool isWhere, Expression> expression) { if (isWhere) _Where(expression); return this; } public ISugarQueryable WhereIF(bool isWhere, Expression> expression) { if (isWhere) _Where(expression); return this; } public ISugarQueryable WhereIF(bool isWhere, Expression> expression) { if (isWhere) _Where(expression); return this; } public ISugarQueryable WhereIF(bool isWhere, Expression> expression) { if (isWhere) _Where(expression); return this; } public ISugarQueryable WhereIF(bool isWhere, Expression> expression) { if (isWhere) _Where(expression); return this; } public ISugarQueryable WhereIF(bool isWhere, Expression> expression) { if (isWhere) _Where(expression); return this; } public ISugarQueryable WhereIF(bool isWhere, Expression> expression) { if (isWhere) _Where(expression); return this; } public ISugarQueryable WhereIF(bool isWhere, Expression> expression) { if (isWhere) _Where(expression); return this; } public new ISugarQueryable Where(string whereString, object whereObj) { Where(whereString, whereObj); return this; } public new ISugarQueryable WhereIF(bool isWhere, string whereString, object whereObj) { if (!isWhere) return this; this.Where(whereString, whereObj); return this; } #endregion #region Select public ISugarQueryable Select(Expression> expression, bool isAutoFill) { var clone = this.Select(expression).Clone(); var sql = clone.QueryBuilder.GetSelectValue; if (this.QueryBuilder.IsSingle() || string.IsNullOrEmpty(sql) || sql.Trim() == "*") { sql = " "; } this.QueryBuilder.Parameters = clone.QueryBuilder.Parameters; this.QueryBuilder.SubToListParameters = clone.QueryBuilder.SubToListParameters; this.QueryBuilder.LambdaExpressions.ParameterIndex = clone.QueryBuilder.LambdaExpressions.ParameterIndex; var parameters = (expression as LambdaExpression).Parameters; var columnsResult = this.Context.EntityMaintenance.GetEntityInfo().Columns; sql = AppendSelect(sql, parameters, columnsResult, 0); sql = AppendSelect(sql, parameters, columnsResult, 1); sql = AppendSelect(sql, parameters, columnsResult, 2); sql = AppendSelect(sql, parameters, columnsResult, 3); sql = AppendSelect(sql, parameters, columnsResult, 4); sql = AppendSelect(sql, parameters, columnsResult, 5); sql = AppendSelect(sql, parameters, columnsResult, 6); sql = AppendSelect(sql, parameters, columnsResult, 7); sql = AppendSelect(sql, parameters, columnsResult, 8); sql = AppendSelect(sql, parameters, columnsResult, 9); sql = AppendSelect (sql, parameters, columnsResult, 10); sql = AppendSelect(sql, parameters, columnsResult, 11); if (sql.Trim().First() == ',') { sql = sql.TrimStart(' ').TrimStart(','); } return this.Select(sql); } public ISugarQueryable Select(Expression> expression) { return _Select(expression); } public ISugarQueryable Select(Expression> expression) { return _Select(expression); } public ISugarQueryable Select(Expression> expression) { return _Select(expression); } public ISugarQueryable Select(Expression> expression) { return _Select(expression); } public ISugarQueryable Select(Expression> expression) { return _Select(expression); } public ISugarQueryable Select(Expression> expression) { return _Select(expression); } public ISugarQueryable Select(Expression> expression) { return _Select(expression); } public ISugarQueryable Select(Expression> expression) { return _Select(expression); } public ISugarQueryable Select(Expression> expression) { return _Select(expression); } public ISugarQueryable Select(Expression> expression) { return _Select(expression); } public ISugarQueryable Select(Expression> expression) { return _Select(expression); } #endregion #region OrderBy public new ISugarQueryable OrderBy(List models) { base.OrderBy(models); return this; } public new ISugarQueryable OrderBy(string orderByFields) { base.OrderBy(orderByFields); return this; } public new ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc) { _OrderBy(expression, type); return this; } public ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc) { _OrderBy(expression, type); return this; } public ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc) { _OrderBy(expression, type); return this; } public ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc) { _OrderBy(expression, type); return this; } public ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc) { _OrderBy(expression, type); return this; } public ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc) { _OrderBy(expression, type); return this; } public ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc) { _OrderBy(expression, type); return this; } public ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc) { _OrderBy(expression, type); return this; } public ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc) { _OrderBy(expression, type); return this; } public ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc) { _OrderBy(expression, type); return this; } public ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc) { _OrderBy(expression, type); return this; } public ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc) { _OrderBy(expression, type); return this; } public new ISugarQueryable OrderByIF(bool isOrderBy, string orderByFields) { if (isOrderBy) base.OrderBy(orderByFields); return this; } public new ISugarQueryable OrderByIF(bool isOrderBy, Expression> expression, OrderByType type = OrderByType.Asc) { if (isOrderBy) _OrderBy(expression, type); return this; } public ISugarQueryable OrderByIF(bool isOrderBy, Expression> expression, OrderByType type = OrderByType.Asc) { if (isOrderBy) _OrderBy(expression, type); return this; } public ISugarQueryable OrderByIF(bool isOrderBy, Expression> expression, OrderByType type = OrderByType.Asc) { if (isOrderBy) _OrderBy(expression, type); return this; } public ISugarQueryable OrderByIF(bool isOrderBy, Expression> expression, OrderByType type = OrderByType.Asc) { if (isOrderBy) _OrderBy(expression, type); return this; } public ISugarQueryable OrderByIF(bool isOrderBy, Expression> expression, OrderByType type = OrderByType.Asc) { if (isOrderBy) _OrderBy(expression, type); return this; } public ISugarQueryable OrderByIF(bool isOrderBy, Expression> expression, OrderByType type = OrderByType.Asc) { if (isOrderBy) _OrderBy(expression, type); return this; } public ISugarQueryable OrderByIF(bool isOrderBy, Expression> expression, OrderByType type = OrderByType.Asc) { if (isOrderBy) _OrderBy(expression, type); return this; } public ISugarQueryable OrderByIF(bool isOrderBy, Expression> expression, OrderByType type = OrderByType.Asc) { if (isOrderBy) _OrderBy(expression, type); return this; } public ISugarQueryable OrderByIF(bool isOrderBy, Expression> expression, OrderByType type = OrderByType.Asc) { if (isOrderBy) _OrderBy(expression, type); return this; } public ISugarQueryable OrderByIF(bool isOrderBy, Expression> expression, OrderByType type = OrderByType.Asc) { if (isOrderBy) _OrderBy(expression, type); return this; } public ISugarQueryable OrderByIF(bool isOrderBy, Expression> expression, OrderByType type = OrderByType.Asc) { if (isOrderBy) _OrderBy(expression, type); return this; } public ISugarQueryable OrderByIF(bool isOrderBy, Expression> expression, OrderByType type = OrderByType.Asc) { if (isOrderBy) _OrderBy(expression, type); return this; } #endregion #region GroupBy public new ISugarQueryable GroupBy(Expression> expression) { _GroupBy(expression); return this; } public ISugarQueryable GroupBy(Expression> expression) { _GroupBy(expression); return this; } public ISugarQueryable GroupBy(Expression> expression) { _GroupBy(expression); return this; } public ISugarQueryable GroupBy(Expression> expression) { _GroupBy(expression); return this; } public ISugarQueryable GroupBy(Expression> expression) { _GroupBy(expression); return this; } public ISugarQueryable GroupBy(Expression> expression) { _GroupBy(expression); return this; } public ISugarQueryable GroupBy(Expression> expression) { _GroupBy(expression); return this; } public ISugarQueryable GroupBy(Expression> expression) { _GroupBy(expression); return this; } public ISugarQueryable GroupBy(Expression> expression) { _GroupBy(expression); return this; } public ISugarQueryable GroupBy(Expression> expression) { _GroupBy(expression); return this; } public ISugarQueryable GroupBy(Expression> expression) { _GroupBy(expression); return this; } public ISugarQueryable GroupBy(Expression> expression) { _GroupBy(expression); return this; } #endregion #region Aggr public TResult Max(Expression> expression) { return _Max(expression); } public TResult Min(Expression> expression) { return _Min(expression); } public TResult Sum(Expression> expression) { return _Sum(expression); } public TResult Avg(Expression> expression) { return _Avg(expression); } #endregion #region In public new ISugarQueryable In(Expression> expression, params FieldType[] inValues) { var isSingle = QueryBuilder.IsSingle(); var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); var fieldName = lamResult.GetResultString(); In(fieldName, inValues); return this; } public new ISugarQueryable In(Expression> expression, List inValues) { var isSingle = QueryBuilder.IsSingle(); var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); var fieldName = lamResult.GetResultString(); In(fieldName, inValues); return this; } public new ISugarQueryable In(Expression> expression, ISugarQueryable childQueryExpression) { var sqlObj = childQueryExpression.ToSql(); _InQueryable(expression, sqlObj); return this; } #endregion #region Other public new ISugarQueryable Distinct() { QueryBuilder.IsDistinct = true; return this; } public new ISugarQueryable Take(int num) { QueryBuilder.Take = num; return this; } public new ISugarQueryable Clone() { var queryable = this.Context.Queryable((t, t2, t3, t4, t5, T6, t7, t8, t9, t10, t11, t12) => new object[] { }).WithCacheIF(IsCache, CacheTime); base.CopyQueryBuilder(queryable.QueryBuilder); return queryable; } public new ISugarQueryable AS(string tableName) { var entityName = typeof(AsT).Name; _As(tableName, entityName); return this; } public new ISugarQueryable AS(string tableName) { var entityName = typeof(T).Name; _As(tableName, entityName); return this; } public new ISugarQueryable ClearFilter() { this.Filter(null, true); return this; } public new ISugarQueryable Filter(string FilterName, bool isDisabledGobalFilter = false) { _Filter(FilterName, isDisabledGobalFilter); return this; } public new ISugarQueryable ClearFilter(params Type[] types) { base.ClearFilter(types); return this; } public new ISugarQueryable ClearFilter() { this.ClearFilter(typeof(FilterType1)); return this; } public new ISugarQueryable ClearFilter() { this.ClearFilter(typeof(FilterType1), typeof(FilterType2)); return this; } public new ISugarQueryable ClearFilter() { this.ClearFilter(typeof(FilterType1), typeof(FilterType2), typeof(FilterType3)); return this; } public new ISugarQueryable AddParameters(object parameters) { if (parameters != null) QueryBuilder.Parameters.AddRange(Context.Ado.GetParameters(parameters)); return this; } public new ISugarQueryable AddParameters(SugarParameter[] parameters) { if (parameters != null) QueryBuilder.Parameters.AddRange(parameters); return this; } public new ISugarQueryable AddParameters(List parameters) { if (parameters != null) QueryBuilder.Parameters.AddRange(parameters); return this; } public new ISugarQueryable AddJoinInfo(string tableName, string shortName, string joinWhere, JoinType type = JoinType.Left) { QueryBuilder.JoinIndex = +1; QueryBuilder.JoinQueryInfos .Add(new JoinQueryInfo() { JoinIndex = QueryBuilder.JoinIndex, TableName = tableName, ShortName = shortName, JoinType = type, JoinWhere = joinWhere }); return this; } public new ISugarQueryable With(string withString) { base.With(withString); return this; } public new ISugarQueryable WithCache(int cacheDurationInSeconds = int.MaxValue) { cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds); this.IsCache = true; this.CacheTime = cacheDurationInSeconds; return this; } public new ISugarQueryable WithCacheIF(bool isCache, int cacheDurationInSeconds = int.MaxValue) { cacheDurationInSeconds = SetCacheTime(cacheDurationInSeconds); if (IsCache) { this.IsCache = true; this.CacheTime = cacheDurationInSeconds; } return this; } #endregion } #endregion }