diff --git a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs new file mode 100644 index 000000000..85fdf0abd --- /dev/null +++ b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableHelper.cs @@ -0,0 +1,1199 @@ +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 +{ + public partial class QueryableProvider : QueryableAccessory, ISugarQueryable + { + #region Private Methods + public virtual KeyValuePair> _ToSql() + { + InitMapping(); + ToSqlBefore(); + string sql = QueryBuilder.ToSqlString(); + RestoreMapping(); + return new KeyValuePair>(sql, QueryBuilder.Parameters); + } + private List GetChildList(Expression> parentIdExpression, string pkName, List list, object rootValue, bool isContainOneself) + { + var exp = (parentIdExpression as LambdaExpression).Body; + if (exp is UnaryExpression) + { + exp = (exp as UnaryExpression).Operand; + } + var parentIdName = (exp as MemberExpression).Member.Name; + var result = BuildChildList(list, pkName, parentIdName, rootValue, isContainOneself); + return result; + } + + private static List BuildChildList(List list, string idName, string pIdName, object rootValue, bool isContainOneself) + { + var type = typeof(T); + var idProp = type.GetProperty(idName); + var pIdProp = type.GetProperty(pIdName); + + var kvpList = list.ToDictionary(x => x, v => idProp.GetValue(v).ObjToString()); + var groupKv = list.GroupBy(x => pIdProp.GetValue(x).ObjToString()).ToDictionary(k => k.Key, v => v.ToList()); + + Func> fc = null; + fc = (rootVal) => + { + var finalList = new List(); + if (groupKv.TryGetValue(rootVal, out var nextChildList)) + { + finalList.AddRange(nextChildList); + foreach (var child in nextChildList) + { + finalList.AddRange(fc(kvpList[child])); + } + } + return finalList; + }; + + var result = fc(rootValue.ObjToString()); + + if (isContainOneself) + { + var root = kvpList.FirstOrDefault(x => x.Value == rootValue.ObjToString()).Key; + if (root != null) + { + result.Insert(0, root); + } + } + + return result; + } + + private List GetTreeRoot(Expression>> childListExpression, Expression> parentIdExpression, string pk, List list, object rootValue) + { + var childName = ((childListExpression as LambdaExpression).Body as MemberExpression).Member.Name; + var exp = (parentIdExpression as LambdaExpression).Body; + if (exp is UnaryExpression) + { + exp = (exp as UnaryExpression).Operand; + } + var parentIdName = (exp as MemberExpression).Member.Name; + + return BuildTree(list, pk, parentIdName, childName, rootValue)?.ToList() ?? default; + } + + private static IEnumerable BuildTree(IEnumerable list, string idName, string pIdName, string childName, object rootValue) + { + var type = typeof(T); + var mainIdProp = type.GetProperty(idName); + var pIdProp = type.GetProperty(pIdName); + var childProp = type.GetProperty(childName); + + var kvList = list.ToDictionary(x => mainIdProp.GetValue(x).ObjToString()); + var group = list.GroupBy(x => pIdProp.GetValue(x).ObjToString()); + + var root = rootValue != null ? group.FirstOrDefault(x => x.Key == rootValue.ObjToString()) : group.FirstOrDefault(x => x.Key == null || x.Key == "" || x.Key == "0" || x.Key == Guid.Empty.ToString()); + + if (root != null) + { + foreach (var item in group) + { + if (kvList.TryGetValue(item.Key, out var parent)) + { + childProp.SetValue(parent, item.ToList()); + } + } + } + + return root; + } + + public List GetTreeChildList(List alllist, object pkValue, string pkName, string childName, string parentIdName) + { + var result = alllist.Where(it => + { + + var value = it.GetType().GetProperty(parentIdName).GetValue(it); + return value.ObjToString() == pkValue.ObjToString(); + + }).ToList(); + if (result != null && result.Count > 0) + { + foreach (var item in result) + { + var itemPkValue = item.GetType().GetProperty(pkName).GetValue(item); + item.GetType().GetProperty(childName).SetValue(item, GetTreeChildList(alllist, itemPkValue, pkName, childName, parentIdName)); + } + } + return result; + } + protected JoinQueryInfo GetJoinInfo(Expression joinExpression, JoinType joinType) + { + QueryBuilder.CheckExpressionNew(joinExpression, "Join"); + QueryBuilder.JoinExpression = joinExpression; + var express = LambdaExpression.Lambda(joinExpression).Body; + var lastPareamter = (express as LambdaExpression).Parameters.Last(); + var expResult = this.QueryBuilder.GetExpressionValue(joinExpression, ResolveExpressType.WhereMultiple); + this.Context.InitMappingInfo(lastPareamter.Type); + var result = new JoinQueryInfo() + { + JoinIndex = QueryBuilder.JoinQueryInfos.Count, + JoinType = joinType, + JoinWhere = expResult.GetResultString(), + ShortName = lastPareamter.Name, + TableName = this.Context.EntityMaintenance.GetTableName(lastPareamter.Type) + }; + if (result.JoinIndex == 0) + { + var firstPareamter = (express as LambdaExpression).Parameters.First(); + this.QueryBuilder.TableShortName = firstPareamter.Name; + if (this.QueryBuilder.AsTables != null && this.QueryBuilder.AsTables.Count == 1) + { + var tableinfo = this.QueryBuilder.AsTables.First(); + if (this.QueryBuilder.TableWithString != SqlWith.Null && this.Context.CurrentConnectionConfig?.MoreSettings?.IsWithNoLockQuery == true && this.QueryBuilder.AsTables.First().Value.ObjToString().Contains(SqlWith.NoLock) == false) + { + this.QueryBuilder.AsTables[tableinfo.Key] = " (SELECT * FROM " + this.QueryBuilder.AsTables.First().Value + $" {SqlWith.NoLock} )"; + } + else + { + this.QueryBuilder.AsTables[tableinfo.Key] = " (SELECT * FROM " + this.QueryBuilder.AsTables.First().Value + ")"; + } + this.QueryBuilder.SelectValue = this.QueryBuilder.TableShortName + ".*"; + } + } + Check.Exception(result.JoinIndex > 10, ErrorMessage.GetThrowMessage("只支持12个表", "Only 12 tables are supported")); + return result; + } + + 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; + } + private static string GetTreeKey(EntityInfo entity) + { + Check.Exception(entity.Columns.Where(it => it.IsPrimarykey || it.IsTreeKey).Count() == 0, "need IsPrimary=true Or IsTreeKey=true"); + string pk = entity.Columns.Where(it => it.IsTreeKey).FirstOrDefault()?.PropertyName; + if (pk == null) + pk = entity.Columns.Where(it => it.IsPrimarykey).FirstOrDefault()?.PropertyName; + return pk; + } + protected ISugarQueryable _Select(Expression expression) + { + QueryBuilder.CheckExpression(expression, "Select"); + this.Context.InitMappingInfo(typeof(TResult)); + var result = InstanceFactory.GetQueryable(this.Context.CurrentConnectionConfig); + result.Context = this.Context; + result.SqlBuilder = this.SqlBuilder; + result.SqlBuilder.QueryBuilder.Parameters = QueryBuilder.Parameters; + result.SqlBuilder.QueryBuilder.SelectValue = expression; + result.SqlBuilder.QueryBuilder.IsSelectSingleFiledJson = UtilMethods.IsJsonMember(expression, this.Context); + if (this.IsCache) + { + result.WithCache(this.CacheTime); + } + if (this.QueryBuilder.IsSqlQuery) + { + this.QueryBuilder.IsSqlQuerySelect = true; + } + return result; + } + protected void _Where(Expression expression) + { + QueryBuilder.CheckExpression(expression, "Where"); + var isSingle = QueryBuilder.IsSingle(); + var result = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.WhereSingle : ResolveExpressType.WhereMultiple); + QueryBuilder.WhereInfos.Add(SqlBuilder.AppendWhereOrAnd(QueryBuilder.WhereInfos.IsNullOrEmpty(), result.GetResultString())); + } + protected ISugarQueryable _OrderBy(Expression expression, OrderByType type = OrderByType.Asc) + { + QueryBuilder.CheckExpression(expression, "OrderBy"); + var isSingle = QueryBuilder.IsSingle(); + if (expression.ToString().IsContainsIn("Desc(", "Asc(")) + { + var orderValue = ""; + var newExp = (expression as LambdaExpression).Body as NewExpression; + foreach (var item in newExp.Arguments) + { + if (item is MemberExpression) + { + orderValue += + QueryBuilder.GetExpressionValue(item, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple).GetResultString() + ","; + } + else + { + orderValue += + QueryBuilder.GetExpressionValue(item, isSingle ? ResolveExpressType.WhereSingle : ResolveExpressType.WhereMultiple).GetResultString() + ","; + } + } + orderValue = orderValue.TrimEnd(','); + OrderBy(orderValue); + return this; + } + else if ((expression as LambdaExpression).Body is NewExpression) + { + var newExp = (expression as LambdaExpression).Body as NewExpression; + var result = ""; + foreach (var item in newExp.Arguments) + { + if (item is MemberExpression) + { + result += + QueryBuilder.GetExpressionValue(item, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple).GetResultString() + ","; + } + else + { + result += + QueryBuilder.GetExpressionValue(item, isSingle ? ResolveExpressType.WhereSingle : ResolveExpressType.WhereMultiple).GetResultString() + ","; + } + } + result = result.TrimEnd(','); + OrderBy(result); + return this; + } + else + { + var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); + OrderBy(lamResult.GetResultString() + UtilConstants.Space + type.ToString().ToUpper()); + return this; + } + } + private void _ToOffsetPage(int pageIndex, int pageSize) + { + QueryBuilder.Offset = $" OFFSET {(pageIndex - 1) * pageSize} ROWS FETCH NEXT {pageSize} ROWS ONLY"; + } + + 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 _GroupBy(Expression expression) + { + QueryBuilder.CheckExpression(expression, "GroupBy"); + LambdaExpression lambda = expression as LambdaExpression; + expression = lambda.Body; + var isSingle = QueryBuilder.IsSingle(); + ExpressionResult lamResult = null; + string result = null; + if (expression is NewExpression) + { + var newExp = expression as NewExpression; + foreach (var item in newExp.Arguments) + { + if (item is MemberExpression) + { + result += + QueryBuilder.GetExpressionValue(item, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple).GetResultString() + ","; + } + else + { + result += + QueryBuilder.GetExpressionValue(item, isSingle ? ResolveExpressType.WhereSingle : ResolveExpressType.WhereMultiple).GetResultString() + ","; + } + } + result = result.TrimEnd(','); + } + else + { + lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); + result = lamResult.GetResultString(); + } + GroupBy(result); + return this; + } + protected TResult _Min(Expression expression) + { + QueryBuilder.CheckExpression(expression, "Main"); + var isSingle = QueryBuilder.IsSingle(); + var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); + var result = Min(lamResult.GetResultString()); + QueryBuilder.SelectValue = null; + return result; + } + protected async Task _MinAsync(Expression expression) + { + QueryBuilder.CheckExpression(expression, "Main"); + var isSingle = QueryBuilder.IsSingle(); + var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); + var result = await MinAsync(lamResult.GetResultString()); + QueryBuilder.SelectValue = null; + return result; + } + protected TResult _Avg(Expression expression) + { + QueryBuilder.CheckExpression(expression, "Avg"); + var isSingle = QueryBuilder.IsSingle(); + var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); + return Avg(lamResult.GetResultString()); + } + protected async Task _AvgAsync(Expression expression) + { + QueryBuilder.CheckExpression(expression, "Avg"); + var isSingle = QueryBuilder.IsSingle(); + var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); + return await AvgAsync(lamResult.GetResultString()); + } + protected TResult _Max(Expression expression) + { + QueryBuilder.CheckExpression(expression, "Max"); + var isSingle = QueryBuilder.IsSingle(); + var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); + var reslut = Max(lamResult.GetResultString()); + QueryBuilder.SelectValue = null; + return reslut; + } + protected async Task _MaxAsync(Expression expression) + { + QueryBuilder.CheckExpression(expression, "Max"); + var isSingle = QueryBuilder.IsSingle(); + var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); + var reslut = await MaxAsync(lamResult.GetResultString()); + QueryBuilder.SelectValue = null; + return reslut; + } + protected TResult _Sum(Expression expression) + { + QueryBuilder.CheckExpression(expression, "Sum"); + var isSingle = QueryBuilder.IsSingle(); + var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); + var reslut = Sum(lamResult.GetResultString()); + QueryBuilder.SelectValue = null; + return reslut; + } + protected async Task _SumAsync(Expression expression) + { + QueryBuilder.CheckExpression(expression, "Sum"); + var isSingle = QueryBuilder.IsSingle(); + var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); + var reslut = await SumAsync(lamResult.GetResultString()); + QueryBuilder.SelectValue = null; + return reslut; + } + protected ISugarQueryable _As(string tableName, string entityName) + { + if (this.QueryBuilder.AsTables != null && this.QueryBuilder.AsTables.Any(it => it.Key == entityName)) + { + Check.Exception(true, ErrorMessage.GetThrowMessage($"use As<{tableName}>(\"{tableName}\")", $"请把 As(\"{tableName}\"), 改成 As<{tableName}实体>(\"{tableName}\")")); + } + else + { + this.QueryBuilder.AsTables.Add(entityName, tableName); + } + return this; + } + protected void _Filter(string FilterName, bool isDisabledGobalFilter) + { + QueryBuilder.IsDisabledGobalFilter = isDisabledGobalFilter; + if (this.Context.QueryFilter.GeFilterList.HasValue() && FilterName.HasValue()) + { + var list = this.Context.QueryFilter.GeFilterList.Where(it => it.FilterName == FilterName && it.IsJoinQuery == !QueryBuilder.IsSingle()); + foreach (var item in list) + { + var filterResult = item.FilterValue(this.Context); + Where(filterResult.Sql + UtilConstants.Space, filterResult.Parameters); + } + } + } + public ISugarQueryable _PartitionBy(Expression expression) + { + QueryBuilder.CheckExpression(expression, "PartitionBy"); + LambdaExpression lambda = expression as LambdaExpression; + expression = lambda.Body; + var isSingle = QueryBuilder.IsSingle(); + ExpressionResult lamResult = null; + string result = null; + if (expression is NewExpression) + { + lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.ArraySingle : ResolveExpressType.ArrayMultiple); + result = string.Join(",", lamResult.GetResultArray()); + } + else + { + lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); + result = lamResult.GetResultString(); + } + PartitionBy(result); + return this; + } + protected ISugarQueryable _Having(Expression expression) + { + QueryBuilder.CheckExpression(expression, "Having"); + var isSingle = QueryBuilder.IsSingle(); + var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.WhereSingle : ResolveExpressType.WhereMultiple); + Having(lamResult.GetResultString()); + return this; + } + protected List _ToList() + { + List result = null; + var sqlObj = this._ToSql(); + if (IsCache) + { + var cacheService = this.Context.CurrentConnectionConfig.ConfigureExternalServices.DataInfoCacheService; + result = CacheSchemeMain.GetOrCreate>(cacheService, this.QueryBuilder, () => { return GetData(sqlObj); }, CacheTime, this.Context, CacheKey); + } + else + { + result = GetData(sqlObj); + } + RestoreMapping(); + _Mapper(result); + _InitNavigat(result); + return result; + } + private async Task _InitNavigatAsync(List result) + { + if (this.QueryBuilder.Includes != null) + { + await Task.Run(() => { _InitNavigat(result); }); + } + } + + private void _InitNavigat(List result) + { + if (this.QueryBuilder.Includes != null) + { + var managers = (this.QueryBuilder.Includes as List); + if (this.QueryBuilder.SelectValue.HasValue() && this.QueryBuilder.NoCheckInclude == false) + { + Check.ExceptionEasy("To use includes, use select after tolist()", "使用Includes请在ToList()之后在使用Select"); + } + foreach (var it in managers) + { + var manager = it as NavigatManager; + manager.RootList = result; + manager.Execute(); + } + } + } + + protected async Task> _ToListAsync() + { + List result = null; + var sqlObj = this._ToSql(); + if (IsCache) + { + var cacheService = this.Context.CurrentConnectionConfig.ConfigureExternalServices.DataInfoCacheService; + result = CacheSchemeMain.GetOrCreate>(cacheService, this.QueryBuilder, () => { return GetData(sqlObj); }, CacheTime, this.Context, CacheKey); + } + else + { + result = await GetDataAsync(sqlObj); + } + RestoreMapping(); + _Mapper(result); + await _InitNavigatAsync(result); + return result; + } + + protected void _Mapper(List result) + { + if (this.EntityInfo.Columns.Any(it => it.IsTranscoding)) + { + foreach (var item in result) + { + foreach (var column in this.EntityInfo.Columns.Where(it => it.IsTranscoding)) + { + var value = column.PropertyInfo.GetValue(item, null); + if (value != null) + { + column.PropertyInfo.SetValue(item, UtilMethods.DecodeBase64(value.ToString()), null); + } + } + } + } + if (this.Mappers.HasValue()) + { + foreach (var mapper in this.Mappers) + { + if (typeof(TResult) == typeof(T)) + { + mapper(result.Select(it => (T)Convert.ChangeType(it, typeof(T))).ToList()); + } + else + { + Check.Exception(true, "{0} and {1} are not a type, Try .select().mapper().ToList", typeof(TResult).FullName, typeof(T).FullName); + } + } + } + if (this.MapperAction != null) + { + foreach (TResult item in result) + { + if (typeof(TResult) == typeof(T)) + { + foreach (var mapper in this.MapperAction) + { + mapper((T)(item as object)); + } + } + else + { + Check.Exception(true, "{0} and {1} are not a type, Try .select().mapper().ToList", typeof(TResult).FullName, typeof(T).FullName); + } + } + } + if (this.MapperActionWithCache != null) + { + if (typeof(TResult) == typeof(T)) + { + var list = (List)Convert.ChangeType(result, typeof(List)); + var mapperCache = new MapperCache(list, this.Context); + foreach (T item in list) + { + mapperCache.GetIndex = 0; + this.MapperActionWithCache(item, mapperCache); + } + } + else + { + Check.Exception(true, "{0} and {1} are not a type, Try .select().mapper().ToList", typeof(TResult).FullName, typeof(T).FullName); + } + } + } + + private ISugarQueryable _Mapper(Expression mapperObject, Expression mapperField) + { + if ((mapperObject as LambdaExpression).Body is UnaryExpression) + { + mapperObject = ((mapperObject as LambdaExpression).Body as UnaryExpression).Operand; + } + else + { + mapperObject = (mapperObject as LambdaExpression).Body; + } + if ((mapperField as LambdaExpression).Body is UnaryExpression) + { + mapperField = ((mapperField as LambdaExpression).Body as UnaryExpression).Operand; + } + else + { + mapperField = (mapperField as LambdaExpression).Body; + } + Check.Exception(mapperObject is MemberExpression == false || mapperField is MemberExpression == false, ".Mapper() parameter error"); + var mapperObjectExp = mapperObject as MemberExpression; + var mapperFieldExp = mapperField as MemberExpression; + Check.Exception(mapperFieldExp.Type.IsClass(), ".Mapper() parameter error"); + var objType = mapperObjectExp.Type; + var filedType = mapperFieldExp.Expression.Type; + Check.Exception(objType != typeof(TObject) && objType != typeof(List), ".Mapper() parameter error"); + if (objType == typeof(List)) + { + objType = typeof(TObject); + } + var filedName = mapperFieldExp.Member.Name; + var objName = mapperObjectExp.Member.Name; + var filedEntity = this.Context.EntityMaintenance.GetEntityInfo(objType); + var objEntity = this.Context.EntityMaintenance.GetEntityInfo(filedType); + var isSelf = filedType == typeof(T); + if (Mappers == null) + Mappers = new List>>(); + if (isSelf) + { + Action> mapper = (entitys) => + { + if (entitys.IsNullOrEmpty() || !entitys.Any()) return; + var entity = entitys.First(); + var whereCol = filedEntity.Columns.FirstOrDefault(it => it.PropertyName.Equals(filedName, StringComparison.CurrentCultureIgnoreCase)); + if (whereCol == null) + { + whereCol = filedEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true); + } + if (whereCol == null) + { + whereCol = filedEntity.Columns.FirstOrDefault(it => GetPrimaryKeys().Any(pk => pk.Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase))); + } + if (whereCol == null) + { + whereCol = filedEntity.Columns.FirstOrDefault(it => it.PropertyName.Equals("id", StringComparison.CurrentCultureIgnoreCase)); + } + if (whereCol == null) + { + whereCol = filedEntity.Columns.FirstOrDefault(it => (it.PropertyName).Equals(it.EntityName + "id", StringComparison.CurrentCultureIgnoreCase)); + } + if (whereCol == null) + { + Check.Exception(true, ".Mapper() parameter error"); + } + List inValues = entitys.Select(it => it.GetType().GetProperty(filedName).GetValue(it, null).ObjToString()).ToList(); + if (inValues != null && inValues.Any() && UtilMethods.GetUnderType(entitys.First().GetType().GetProperty(filedName).PropertyType) == UtilConstants.GuidType) + { + inValues = inValues.Select(x => x == "" ? "null" : x).Distinct().ToList(); + } + List wheres = new List() + { + new ConditionalModel() + { + FieldName=this.SqlBuilder.GetTranslationColumnName(whereCol.DbColumnName), + ConditionalType= ConditionalType.In, + FieldValue=string.Join(",",inValues.Distinct()), + CSharpTypeName=whereCol.PropertyInfo.PropertyType.Name + } + }; + var list = this.Context.Queryable().Where(wheres).ToList(); + foreach (var item in entitys) + { + var whereValue = item.GetType().GetProperty(filedName).GetValue(item, null); + var setValue = list.Where(x => x.GetType().GetProperty(whereCol.PropertyName).GetValue(x, null).ObjToString() == whereValue.ObjToString()).ToList(); + var setObject = item.GetType().GetProperty(objName); + if (setObject.PropertyType.FullName.IsCollectionsList()) + { + setObject.SetValue(item, setValue.ToList(), null); + } + else + { + setObject.SetValue(item, setValue.FirstOrDefault(), null); + } + } + }; + Mappers.Add(mapper); + } + else + { + Action> mapper = (entitys) => + { + if (entitys.IsNullOrEmpty() || !entitys.Any()) return; + var entity = entitys.First(); + var tEntity = this.Context.EntityMaintenance.GetEntityInfo(); + var whereCol = tEntity.Columns.FirstOrDefault(it => it.PropertyName.Equals(filedName, StringComparison.CurrentCultureIgnoreCase)); + if (whereCol == null) + { + whereCol = tEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true); + } + if (whereCol == null) + { + whereCol = tEntity.Columns.FirstOrDefault(it => GetPrimaryKeys().Any(pk => pk.Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase))); + } + if (whereCol == null) + { + whereCol = tEntity.Columns.FirstOrDefault(it => it.PropertyName.Equals("id", StringComparison.CurrentCultureIgnoreCase)); + } + if (whereCol == null) + { + whereCol = tEntity.Columns.FirstOrDefault(it => (it.PropertyName).Equals(it.EntityName + "id", StringComparison.CurrentCultureIgnoreCase)); + } + if (whereCol == null) + { + Check.Exception(true, ".Mapper() parameter error"); + } + List inValues = entitys.Select(it => it.GetType().GetProperty(whereCol.PropertyName).GetValue(it, null).ObjToString()).ToList(); + var dbColumnName = filedEntity.Columns.FirstOrDefault(it => it.PropertyName == filedName).DbColumnName; + List wheres = new List() + { + new ConditionalModel() + { + FieldName=dbColumnName, + ConditionalType= ConditionalType.In, + FieldValue=string.Join(",",inValues) + } + }; + var list = this.Context.Queryable().Where(wheres).ToList(); + foreach (var item in entitys) + { + var whereValue = item.GetType().GetProperty(whereCol.PropertyName).GetValue(item, null); + var setValue = list.Where(x => x.GetType().GetProperty(filedName).GetValue(x, null).ObjToString() == whereValue.ObjToString()).ToList(); + var setObject = item.GetType().GetProperty(objName); + if (setObject.PropertyType.FullName.IsCollectionsList()) + { + setObject.SetValue(item, setValue.ToList(), null); + } + else + { + setObject.SetValue(item, setValue.FirstOrDefault(), null); + } + } + }; + Mappers.Add(mapper); + } + + return this; + } + + private ISugarQueryable _Mapper(Expression mapperObject, Expression mainField, Expression childField) + { + if ((mapperObject as LambdaExpression).Body is UnaryExpression) + { + mapperObject = ((mapperObject as LambdaExpression).Body as UnaryExpression).Operand; + } + else + { + mapperObject = (mapperObject as LambdaExpression).Body; + } + if ((mainField as LambdaExpression).Body is UnaryExpression) + { + mainField = ((mainField as LambdaExpression).Body as UnaryExpression).Operand; + } + else + { + mainField = (mainField as LambdaExpression).Body; + } + if ((childField as LambdaExpression).Body is UnaryExpression) + { + childField = ((childField as LambdaExpression).Body as UnaryExpression).Operand; + } + else + { + childField = (childField as LambdaExpression).Body; + } + Check.Exception(mapperObject is MemberExpression == false || mainField is MemberExpression == false, ".Mapper() parameter error"); + var mapperObjectExp = mapperObject as MemberExpression; + var mainFieldExp = mainField as MemberExpression; + var childFieldExp = childField as MemberExpression; + Check.Exception(mainFieldExp.Type.IsClass(), ".Mapper() parameter error"); + Check.Exception(childFieldExp.Type.IsClass(), ".Mapper() parameter error"); + var objType = mapperObjectExp.Type; + var filedType = mainFieldExp.Expression.Type; + Check.Exception(objType != typeof(TObject) && objType != typeof(List), ".Mapper() parameter error"); + if (objType == typeof(List)) + { + objType = typeof(TObject); + } + var mainFiledName = mainFieldExp.Member.Name; + var childFiledName = childFieldExp.Member.Name; + var objName = mapperObjectExp.Member.Name; + var filedEntity = this.Context.EntityMaintenance.GetEntityInfo(objType); + var objEntity = this.Context.EntityMaintenance.GetEntityInfo(filedType); + var isSelf = filedType == typeof(T); + if (Mappers == null) + Mappers = new List>>(); + if (isSelf) + { + Action> mapper = (entitys) => + { + if (entitys.IsNullOrEmpty() || !entitys.Any()) return; + var entity = entitys.First(); + var whereCol = filedEntity.Columns.FirstOrDefault(it => it.PropertyName.Equals(childFiledName, StringComparison.CurrentCultureIgnoreCase)); + if (whereCol == null) + { + whereCol = filedEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true); + } + if (whereCol == null) + { + whereCol = filedEntity.Columns.FirstOrDefault(it => GetPrimaryKeys().Any(pk => pk.Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase))); + } + if (whereCol == null) + { + whereCol = filedEntity.Columns.FirstOrDefault(it => it.PropertyName.Equals("id", StringComparison.CurrentCultureIgnoreCase)); + } + if (whereCol == null) + { + whereCol = filedEntity.Columns.FirstOrDefault(it => (it.PropertyName).Equals(it.EntityName + "id", StringComparison.CurrentCultureIgnoreCase)); + } + if (whereCol == null) + { + Check.Exception(true, ".Mapper() parameter error"); + } + List inValues = entitys.Select(it => it.GetType().GetProperty(mainFiledName).GetValue(it, null).ObjToString()).ToList(); + List wheres = new List() + { + new ConditionalModel() + { + FieldName=whereCol.DbColumnName, + ConditionalType= ConditionalType.In, + FieldValue=string.Join(",",inValues.Distinct()) + } + }; + var list = this.Context.Queryable().Where(wheres).ToList(); + foreach (var item in entitys) + { + var whereValue = item.GetType().GetProperty(mainFiledName).GetValue(item, null); + var setValue = list.Where(x => x.GetType().GetProperty(whereCol.PropertyName).GetValue(x, null).ObjToString() == whereValue.ObjToString()).ToList(); + var setObject = item.GetType().GetProperty(objName); + if (setObject.PropertyType.FullName.IsCollectionsList()) + { + setObject.SetValue(item, setValue.ToList(), null); + } + else + { + setObject.SetValue(item, setValue.FirstOrDefault(), null); + } + } + }; + Mappers.Add(mapper); + } + else + { + Action> mapper = (entitys) => + { + if (entitys.IsNullOrEmpty() || !entitys.Any()) return; + var entity = entitys.First(); + var tEntity = this.Context.EntityMaintenance.GetEntityInfo(); + var whereCol = tEntity.Columns.FirstOrDefault(it => it.PropertyName.Equals(childFiledName, StringComparison.CurrentCultureIgnoreCase)); + if (whereCol == null) + { + whereCol = tEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true); + } + if (whereCol == null) + { + whereCol = tEntity.Columns.FirstOrDefault(it => GetPrimaryKeys().Any(pk => pk.Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase))); + } + if (whereCol == null) + { + whereCol = tEntity.Columns.FirstOrDefault(it => it.PropertyName.Equals("id", StringComparison.CurrentCultureIgnoreCase)); + } + if (whereCol == null) + { + whereCol = tEntity.Columns.FirstOrDefault(it => (it.PropertyName).Equals(it.EntityName + "id", StringComparison.CurrentCultureIgnoreCase)); + } + if (whereCol == null) + { + Check.Exception(true, ".Mapper() parameter error"); + } + List inValues = entitys.Select(it => it.GetType().GetProperty(whereCol.PropertyName).GetValue(it, null).ObjToString()).ToList(); + var dbColumnName = filedEntity.Columns.FirstOrDefault(it => it.PropertyName == mainFiledName).DbColumnName; + List wheres = new List() + { + new ConditionalModel() + { + FieldName=dbColumnName, + ConditionalType= ConditionalType.In, + FieldValue=string.Join(",",inValues) + } + }; + var list = this.Context.Queryable().Where(wheres).ToList(); + foreach (var item in entitys) + { + var whereValue = item.GetType().GetProperty(whereCol.PropertyName).GetValue(item, null); + var setValue = list.Where(x => x.GetType().GetProperty(mainFiledName).GetValue(x, null).ObjToString() == whereValue.ObjToString()).ToList(); + var setObject = item.GetType().GetProperty(objName); + if (setObject.PropertyType.FullName.IsCollectionsList()) + { + setObject.SetValue(item, setValue.ToList(), null); + } + else + { + setObject.SetValue(item, setValue.FirstOrDefault(), null); + } + } + }; + Mappers.Add(mapper); + } + + return this; + } + protected int GetCount() + { + var sql = string.Empty; + ToSqlBefore(); + sql = QueryBuilder.ToSqlString(); + sql = QueryBuilder.ToCountSql(sql); + var result = Context.Ado.GetInt(sql, QueryBuilder.Parameters.ToArray()); + return result; + } + protected async Task 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() + { + var moreSetts = this.Context.CurrentConnectionConfig.MoreSettings; + if (moreSetts != null && moreSetts.IsWithNoLockQuery && string.IsNullOrEmpty(QueryBuilder.TableWithString)) + { + this.With(SqlWith.NoLock); + } + } + + protected List GetData(KeyValuePair> sqlObj) + { + List result; + var isComplexModel = QueryBuilder.IsComplexModel(sqlObj.Key); + var entityType = typeof(TResult); + bool isChangeQueryableSlave = GetIsSlaveQuery(); + bool isChangeQueryableMasterSlave = GetIsMasterQuery(); + var dataReader = this.Db.GetDataReader(sqlObj.Key, sqlObj.Value.ToArray()); + result = GetData(isComplexModel, entityType, dataReader); + RestChangeMasterQuery(isChangeQueryableMasterSlave); + RestChangeSlaveQuery(isChangeQueryableSlave); + return result; + } + + private void RestChangeMasterQuery(bool isChangeQueryableMasterSlave) + { + if (isChangeQueryableMasterSlave) + this.Context.Ado.IsDisableMasterSlaveSeparation = false; + } + + private bool GetIsMasterQuery() + { + var isChangeQueryableMasterSlave = + this.QueryBuilder.IsDisableMasterSlaveSeparation == true && + this.Context.Ado.IsDisableMasterSlaveSeparation == false && + this.Context.Ado.Transaction == null; + if (isChangeQueryableMasterSlave) + this.Context.Ado.IsDisableMasterSlaveSeparation = true; + return isChangeQueryableMasterSlave; + } + + private void RestChangeSlaveQuery(bool isChangeQueryableSlaveSlave) + { + if (isChangeQueryableSlaveSlave) + this.Context.Ado.IsDisableMasterSlaveSeparation = true; + } + + private bool GetIsSlaveQuery() + { + var isChangeQueryableMasterSlave = + this.QueryBuilder.IsEnableMasterSlaveSeparation == true && + this.Context.Ado.IsDisableMasterSlaveSeparation == true && + this.Context.Ado.Transaction == null; + if (isChangeQueryableMasterSlave) + this.Context.Ado.IsDisableMasterSlaveSeparation = false; + return isChangeQueryableMasterSlave; + } + + protected async Task> GetDataAsync(KeyValuePair> sqlObj) + { + List result; + var isComplexModel = QueryBuilder.IsComplexModel(sqlObj.Key); + var entityType = typeof(TResult); + bool isChangeQueryableSlave = GetIsSlaveQuery(); + bool isChangeQueryableMasterSlave = GetIsMasterQuery(); + var dataReader = await this.Db.GetDataReaderAsync(sqlObj.Key, sqlObj.Value.ToArray()); + result = await GetDataAsync(isComplexModel, entityType, dataReader); + RestChangeMasterQuery(isChangeQueryableMasterSlave); + RestChangeSlaveQuery(isChangeQueryableSlave); + return result; + } + + private List GetData(bool isComplexModel, Type entityType, IDataReader dataReader) + { + List result; + if (entityType == UtilConstants.DynamicType) + { + result = this.Context.Utilities.DataReaderToExpandoObjectList(dataReader) as List; + } + else if (entityType == UtilConstants.ObjType) + { + result = this.Context.Utilities.DataReaderToExpandoObjectList(dataReader).Select(it => ((TResult)(object)it)).ToList(); + } + else if (QueryBuilder.IsSelectSingleFiledJson) + { + result = this.Context.Utilities.DataReaderToSelectJsonList(dataReader); + } + else if (entityType.IsAnonymousType() || isComplexModel) + { + result = this.Context.Utilities.DataReaderToList(dataReader); + } + else + { + result = this.Bind.DataReaderToList(entityType, dataReader); + } + SetContextModel(result, entityType); + return result; + } + private async Task> GetDataAsync(bool isComplexModel, Type entityType, IDataReader dataReader) + { + List result; + if (entityType == UtilConstants.DynamicType) + { + result = await this.Context.Utilities.DataReaderToExpandoObjectListAsync(dataReader) as List; + } + else if (entityType == UtilConstants.ObjType) + { + var expObj = await this.Context.Utilities.DataReaderToExpandoObjectListAsync(dataReader); + result = expObj.Select(it => ((TResult)(object)it)).ToList(); + } + else if (QueryBuilder.IsSelectSingleFiledJson) + { + result = await this.Context.Utilities.DataReaderToSelectJsonListAsync(dataReader); + } + else if (entityType.IsAnonymousType() || isComplexModel) + { + result = await this.Context.Utilities.DataReaderToListAsync(dataReader); + } + else + { + result = await this.Bind.DataReaderToListAsync(entityType, dataReader); + } + SetContextModel(result, entityType); + return result; + } + + protected void _InQueryable(Expression expression, KeyValuePair> sqlObj) + { + QueryBuilder.CheckExpression(expression, "In"); + string sql = sqlObj.Key; + if (sqlObj.Value.HasValue()) + { + this.SqlBuilder.RepairReplicationParameters(ref sql, sqlObj.Value.ToArray(), 100); + this.QueryBuilder.Parameters.AddRange(sqlObj.Value); + } + var isSingle = QueryBuilder.IsSingle(); + var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); + var fieldName = lamResult.GetResultString(); + var whereSql = string.Format(this.QueryBuilder.InTemplate, fieldName, sql); + this.QueryBuilder.WhereInfos.Add(SqlBuilder.AppendWhereOrAnd(this.QueryBuilder.WhereInfos.IsNullOrEmpty(), whereSql)); + base._InQueryableIndex += 100; + } + + protected List GetPrimaryKeys() + { + if (this.Context.IsSystemTablesConfig) + { + return this.Context.DbMaintenance.GetPrimaries(this.Context.EntityMaintenance.GetTableName(this.EntityInfo.EntityName)); + } + else + { + return this.EntityInfo.Columns.Where(it => it.IsPrimarykey).Select(it => it.DbColumnName).ToList(); + } + } + protected virtual List GetIdentityKeys() + { + if (this.Context.IsSystemTablesConfig) + { + return this.Context.DbMaintenance.GetIsIdentities(this.EntityInfo.DbTableName); + } + else + { + return this.EntityInfo.Columns.Where(it => it.IsIdentity).Select(it => it.DbColumnName).ToList(); + } + } + + protected void RestoreMapping() + { + if (IsAs && _RestoreMapping) + { + this.Context.MappingTables = OldMappingTableList == null ? new MappingTableList() : OldMappingTableList; + } + } + protected void InitMapping() + { + if (this.QueryableMappingTableList != null) + this.Context.MappingTables = this.QueryableMappingTableList; + } + + private void SetContextModel(List result, Type entityType) + { + if (result.HasValue()) + { + if (UtilMethods.GetRootBaseType(entityType).HasValue() && UtilMethods.GetRootBaseType(entityType) == UtilConstants.ModelType) + { + foreach (var item in result) + { + 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); + } + } + } + } + protected void CopyQueryBuilder(QueryBuilder asyncQueryableBuilder) + { + var pars = new List(); + if (this.QueryBuilder.Parameters != null) + { + pars = this.QueryBuilder.Parameters.Select(it => new SugarParameter(it.ParameterName, it.Value) + { + DbType = it.DbType, + Value = it.Value, + ParameterName = it.ParameterName, + Direction = it.Direction, + IsArray = it.IsArray, + IsJson = it.IsJson, + IsNullable = it.IsNullable, + IsRefCursor = it.IsRefCursor, + Size = it.Size, + SourceColumn = it.SourceColumn, + SourceColumnNullMapping = it.SourceColumnNullMapping, + SourceVersion = it.SourceVersion, + TempDate = it.TempDate, + TypeName = it.TypeName, + UdtTypeName = it.UdtTypeName, + _Size = it._Size + }).ToList(); + } + asyncQueryableBuilder.IsEnableMasterSlaveSeparation = this.QueryBuilder.IsEnableMasterSlaveSeparation; + asyncQueryableBuilder.TranLock = this.QueryBuilder.TranLock; + asyncQueryableBuilder.IsDisableMasterSlaveSeparation = this.QueryBuilder.IsDisableMasterSlaveSeparation; + asyncQueryableBuilder.IsQueryInQuery = this.QueryBuilder.IsQueryInQuery; + asyncQueryableBuilder.Includes = this.QueryBuilder.Includes; + asyncQueryableBuilder.Take = this.QueryBuilder.Take; + asyncQueryableBuilder.Skip = this.QueryBuilder.Skip; + asyncQueryableBuilder.SelectValue = this.QueryBuilder.SelectValue; + asyncQueryableBuilder.WhereInfos = this.Context.Utilities.TranslateCopy(this.QueryBuilder.WhereInfos); + asyncQueryableBuilder.EasyJoinInfos = this.Context.Utilities.TranslateCopy(this.QueryBuilder.EasyJoinInfos); + asyncQueryableBuilder.JoinQueryInfos = this.Context.Utilities.TranslateCopy(this.QueryBuilder.JoinQueryInfos); + asyncQueryableBuilder.WhereIndex = this.QueryBuilder.WhereIndex; + asyncQueryableBuilder.EntityType = this.QueryBuilder.EntityType; + asyncQueryableBuilder.EntityName = this.QueryBuilder.EntityName; + asyncQueryableBuilder.Parameters = pars; + asyncQueryableBuilder.TableShortName = this.QueryBuilder.TableShortName; + asyncQueryableBuilder.TableWithString = this.QueryBuilder.TableWithString; + asyncQueryableBuilder.GroupByValue = this.QueryBuilder.GroupByValue; + asyncQueryableBuilder.IsDistinct = this.QueryBuilder.IsDistinct; + asyncQueryableBuilder.OrderByValue = this.QueryBuilder.OrderByValue; + asyncQueryableBuilder.IsDisabledGobalFilter = this.QueryBuilder.IsDisabledGobalFilter; + asyncQueryableBuilder.PartitionByValue = this.QueryBuilder.PartitionByValue; + asyncQueryableBuilder.JoinExpression = this.QueryBuilder.JoinExpression; + asyncQueryableBuilder.WhereIndex = this.QueryBuilder.WhereIndex; + asyncQueryableBuilder.HavingInfos = this.QueryBuilder.HavingInfos; + asyncQueryableBuilder.LambdaExpressions.ParameterIndex = this.QueryBuilder.LambdaExpressions.ParameterIndex; + asyncQueryableBuilder.IgnoreColumns = this.Context.Utilities.TranslateCopy(this.QueryBuilder.IgnoreColumns); + asyncQueryableBuilder.AsTables = this.Context.Utilities.TranslateCopy(this.QueryBuilder.AsTables); + asyncQueryableBuilder.DisableTop = this.QueryBuilder.DisableTop; + asyncQueryableBuilder.Offset = this.QueryBuilder.Offset; + asyncQueryableBuilder.IsSqlQuery = this.QueryBuilder.IsSqlQuery; + asyncQueryableBuilder.IsSqlQuerySelect = this.QueryBuilder.IsSqlQuerySelect; + asyncQueryableBuilder.OldSql = this.QueryBuilder.OldSql; + asyncQueryableBuilder.IsCrossQueryWithAttr = this.QueryBuilder.IsCrossQueryWithAttr; + asyncQueryableBuilder.CrossQueryItems = this.QueryBuilder.CrossQueryItems; + } + protected int SetCacheTime(int cacheDurationInSeconds) + { + if (cacheDurationInSeconds == int.MaxValue && this.Context.CurrentConnectionConfig.MoreSettings != null && this.Context.CurrentConnectionConfig.MoreSettings.DefaultCacheDurationInSeconds > 0) + { + cacheDurationInSeconds = this.Context.CurrentConnectionConfig.MoreSettings.DefaultCacheDurationInSeconds; + } + + return cacheDurationInSeconds; + } + + #endregion + } +} diff --git a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs index 9c4cf3ef9..3d9c1ac5d 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs @@ -2441,7353 +2441,6 @@ namespace SqlSugar } #endregion - - #region Private Methods - public virtual KeyValuePair> _ToSql() - { - InitMapping(); - ToSqlBefore(); - string sql = QueryBuilder.ToSqlString(); - RestoreMapping(); - return new KeyValuePair>(sql, QueryBuilder.Parameters); - } - private List GetChildList(Expression> parentIdExpression, string pkName, List list, object rootValue, bool isContainOneself) - { - var exp = (parentIdExpression as LambdaExpression).Body; - if (exp is UnaryExpression) - { - exp = (exp as UnaryExpression).Operand; - } - var parentIdName = (exp as MemberExpression).Member.Name; - var result = BuildChildList(list, pkName, parentIdName, rootValue, isContainOneself); - return result; - } - - private static List BuildChildList(List list, string idName, string pIdName, object rootValue, bool isContainOneself) - { - var type = typeof(T); - var idProp = type.GetProperty(idName); - var pIdProp = type.GetProperty(pIdName); - - var kvpList = list.ToDictionary(x => x, v => idProp.GetValue(v).ObjToString()); - var groupKv = list.GroupBy(x => pIdProp.GetValue(x).ObjToString()).ToDictionary(k => k.Key, v => v.ToList()); - - Func> fc = null; - fc = (rootVal) => - { - var finalList = new List(); - if (groupKv.TryGetValue(rootVal, out var nextChildList)) - { - finalList.AddRange(nextChildList); - foreach (var child in nextChildList) - { - finalList.AddRange(fc(kvpList[child])); - } - } - return finalList; - }; - - var result = fc(rootValue.ObjToString()); - - if (isContainOneself) - { - var root = kvpList.FirstOrDefault(x => x.Value == rootValue.ObjToString()).Key; - if (root != null) - { - result.Insert(0, root); - } - } - - return result; - } - - private List GetTreeRoot(Expression>> childListExpression, Expression> parentIdExpression, string pk, List list,object rootValue) - { - var childName = ((childListExpression as LambdaExpression).Body as MemberExpression).Member.Name; - var exp = (parentIdExpression as LambdaExpression).Body; - if (exp is UnaryExpression) - { - exp = (exp as UnaryExpression).Operand; - } - var parentIdName = (exp as MemberExpression).Member.Name; - - return BuildTree(list, pk, parentIdName, childName, rootValue)?.ToList() ?? default; - } - - private static IEnumerable BuildTree(IEnumerable list, string idName, string pIdName, string childName, object rootValue) - { - var type = typeof(T); - var mainIdProp = type.GetProperty(idName); - var pIdProp = type.GetProperty(pIdName); - var childProp = type.GetProperty(childName); - - var kvList = list.ToDictionary(x => mainIdProp.GetValue(x).ObjToString()); - var group = list.GroupBy(x => pIdProp.GetValue(x).ObjToString()); - - var root = rootValue != null ? group.FirstOrDefault(x => x.Key == rootValue.ObjToString()) : group.FirstOrDefault(x => x.Key == null || x.Key == "" || x.Key == "0" || x.Key == Guid.Empty.ToString()); - - if (root != null) - { - foreach (var item in group) - { - if (kvList.TryGetValue(item.Key, out var parent)) - { - childProp.SetValue(parent, item.ToList()); - } - } - } - - return root; - } - - public List GetTreeChildList(List alllist, object pkValue, string pkName, string childName, string parentIdName) - { - var result = alllist.Where(it => - { - - var value = it.GetType().GetProperty(parentIdName).GetValue(it); - return value.ObjToString() == pkValue.ObjToString(); - - }).ToList(); - if (result != null && result.Count > 0) - { - foreach (var item in result) - { - var itemPkValue = item.GetType().GetProperty(pkName).GetValue(item); - item.GetType().GetProperty(childName).SetValue(item, GetTreeChildList(alllist, itemPkValue, pkName, childName, parentIdName)); - } - } - return result; - } - protected JoinQueryInfo GetJoinInfo(Expression joinExpression,JoinType joinType) - { - QueryBuilder.CheckExpressionNew(joinExpression, "Join"); - QueryBuilder.JoinExpression = joinExpression; - var express= LambdaExpression.Lambda(joinExpression).Body; - var lastPareamter= (express as LambdaExpression).Parameters.Last(); - var expResult = this.QueryBuilder.GetExpressionValue(joinExpression, ResolveExpressType.WhereMultiple); - this.Context.InitMappingInfo(lastPareamter.Type); - var result= new JoinQueryInfo() - { - JoinIndex = QueryBuilder.JoinQueryInfos.Count, - JoinType = joinType, - JoinWhere = expResult.GetResultString(), - ShortName= lastPareamter.Name, - TableName=this.Context.EntityMaintenance.GetTableName(lastPareamter.Type) - }; - if (result.JoinIndex == 0) - { - var firstPareamter = (express as LambdaExpression).Parameters.First(); - this.QueryBuilder.TableShortName = firstPareamter.Name; - if (this.QueryBuilder.AsTables != null && this.QueryBuilder.AsTables.Count==1) - { - var tableinfo = this.QueryBuilder.AsTables.First(); - if (this.QueryBuilder.TableWithString!=SqlWith.Null&&this.Context.CurrentConnectionConfig?.MoreSettings?.IsWithNoLockQuery == true&& this.QueryBuilder.AsTables.First().Value.ObjToString().Contains(SqlWith.NoLock) ==false) - { - this.QueryBuilder.AsTables[tableinfo.Key] = " (SELECT * FROM " + this.QueryBuilder.AsTables.First().Value + $" {SqlWith.NoLock} )"; - } - else - { - this.QueryBuilder.AsTables[tableinfo.Key] = " (SELECT * FROM " + this.QueryBuilder.AsTables.First().Value + ")"; - } - this.QueryBuilder.SelectValue = this.QueryBuilder.TableShortName +".*"; - } - } - Check.Exception(result.JoinIndex > 10, ErrorMessage.GetThrowMessage("只支持12个表", "Only 12 tables are supported")); - return result; - } - - 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; - } - private static string GetTreeKey(EntityInfo entity) - { - Check.Exception(entity.Columns.Where(it => it.IsPrimarykey || it.IsTreeKey).Count() == 0, "need IsPrimary=true Or IsTreeKey=true"); - string pk = entity.Columns.Where(it => it.IsTreeKey).FirstOrDefault()?.PropertyName; - if (pk == null) - pk = entity.Columns.Where(it => it.IsPrimarykey).FirstOrDefault()?.PropertyName; - return pk; - } - protected ISugarQueryable _Select(Expression expression) - { - QueryBuilder.CheckExpression(expression, "Select"); - this.Context.InitMappingInfo(typeof(TResult)); - var result = InstanceFactory.GetQueryable(this.Context.CurrentConnectionConfig); - result.Context = this.Context; - result.SqlBuilder = this.SqlBuilder; - result.SqlBuilder.QueryBuilder.Parameters = QueryBuilder.Parameters; - result.SqlBuilder.QueryBuilder.SelectValue = expression; - result.SqlBuilder.QueryBuilder.IsSelectSingleFiledJson = UtilMethods.IsJsonMember(expression,this.Context); - if (this.IsCache) - { - result.WithCache(this.CacheTime); - } - if (this.QueryBuilder.IsSqlQuery) - { - this.QueryBuilder.IsSqlQuerySelect = true; - } - return result; - } - protected void _Where(Expression expression) - { - QueryBuilder.CheckExpression(expression, "Where"); - var isSingle = QueryBuilder.IsSingle(); - var result = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.WhereSingle : ResolveExpressType.WhereMultiple); - QueryBuilder.WhereInfos.Add(SqlBuilder.AppendWhereOrAnd(QueryBuilder.WhereInfos.IsNullOrEmpty(), result.GetResultString())); - } - protected ISugarQueryable _OrderBy(Expression expression, OrderByType type = OrderByType.Asc) - { - QueryBuilder.CheckExpression(expression, "OrderBy"); - var isSingle = QueryBuilder.IsSingle(); - if (expression.ToString().IsContainsIn("Desc(", "Asc(")) - { - var orderValue = ""; - var newExp = (expression as LambdaExpression).Body as NewExpression; - foreach (var item in newExp.Arguments) - { - if (item is MemberExpression) - { - orderValue += - QueryBuilder.GetExpressionValue(item, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple).GetResultString() + ","; - } - else - { - orderValue += - QueryBuilder.GetExpressionValue(item, isSingle ? ResolveExpressType.WhereSingle : ResolveExpressType.WhereMultiple).GetResultString() + ","; - } - } - orderValue = orderValue.TrimEnd(','); - OrderBy(orderValue); - return this; - } - else if ((expression as LambdaExpression).Body is NewExpression) - { - var newExp = (expression as LambdaExpression).Body as NewExpression; - var result = ""; - foreach (var item in newExp.Arguments) - { - if (item is MemberExpression) - { - result += - QueryBuilder.GetExpressionValue(item, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple).GetResultString() + ","; - } - else - { - result += - QueryBuilder.GetExpressionValue(item, isSingle ? ResolveExpressType.WhereSingle : ResolveExpressType.WhereMultiple).GetResultString() + ","; - } - } - result = result.TrimEnd(','); - OrderBy(result); - return this; - } - else - { - var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); - OrderBy(lamResult.GetResultString() + UtilConstants.Space + type.ToString().ToUpper()); - return this; - } - } - private void _ToOffsetPage(int pageIndex, int pageSize) - { - QueryBuilder.Offset = $" OFFSET {(pageIndex - 1) * pageSize} ROWS FETCH NEXT {pageSize} ROWS ONLY"; - } - - 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 _GroupBy(Expression expression) - { - QueryBuilder.CheckExpression(expression, "GroupBy"); - LambdaExpression lambda = expression as LambdaExpression; - expression = lambda.Body; - var isSingle = QueryBuilder.IsSingle(); - ExpressionResult lamResult = null; - string result = null; - if (expression is NewExpression) - { - var newExp=expression as NewExpression; - foreach (var item in newExp.Arguments) - { - if (item is MemberExpression) - { - result += - QueryBuilder.GetExpressionValue(item, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple).GetResultString() + ","; - } - else - { - result += - QueryBuilder.GetExpressionValue(item, isSingle ? ResolveExpressType.WhereSingle : ResolveExpressType.WhereMultiple).GetResultString() + ","; - } - } - result = result.TrimEnd(','); - } - else - { - lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); - result = lamResult.GetResultString(); - } - GroupBy(result); - return this; - } - protected TResult _Min(Expression expression) - { - QueryBuilder.CheckExpression(expression, "Main"); - var isSingle = QueryBuilder.IsSingle(); - var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); - var result = Min(lamResult.GetResultString()); - QueryBuilder.SelectValue = null; - return result; - } - protected async Task _MinAsync(Expression expression) - { - QueryBuilder.CheckExpression(expression, "Main"); - var isSingle = QueryBuilder.IsSingle(); - var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); - var result = await MinAsync(lamResult.GetResultString()); - QueryBuilder.SelectValue = null; - return result; - } - protected TResult _Avg(Expression expression) - { - QueryBuilder.CheckExpression(expression, "Avg"); - var isSingle = QueryBuilder.IsSingle(); - var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); - return Avg(lamResult.GetResultString()); - } - protected async Task _AvgAsync(Expression expression) - { - QueryBuilder.CheckExpression(expression, "Avg"); - var isSingle = QueryBuilder.IsSingle(); - var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); - return await AvgAsync(lamResult.GetResultString()); - } - protected TResult _Max(Expression expression) - { - QueryBuilder.CheckExpression(expression, "Max"); - var isSingle = QueryBuilder.IsSingle(); - var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); - var reslut = Max(lamResult.GetResultString()); - QueryBuilder.SelectValue = null; - return reslut; - } - protected async Task _MaxAsync(Expression expression) - { - QueryBuilder.CheckExpression(expression, "Max"); - var isSingle = QueryBuilder.IsSingle(); - var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); - var reslut =await MaxAsync(lamResult.GetResultString()); - QueryBuilder.SelectValue = null; - return reslut; - } - protected TResult _Sum(Expression expression) - { - QueryBuilder.CheckExpression(expression, "Sum"); - var isSingle = QueryBuilder.IsSingle(); - var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); - var reslut = Sum(lamResult.GetResultString()); - QueryBuilder.SelectValue = null; - return reslut; - } - protected async Task _SumAsync(Expression expression) - { - QueryBuilder.CheckExpression(expression, "Sum"); - var isSingle = QueryBuilder.IsSingle(); - var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); - var reslut =await SumAsync(lamResult.GetResultString()); - QueryBuilder.SelectValue = null; - return reslut; - } - protected ISugarQueryable _As(string tableName, string entityName) - { - if (this.QueryBuilder.AsTables != null && this.QueryBuilder.AsTables.Any(it => it.Key == entityName)) - { - Check.Exception(true, ErrorMessage.GetThrowMessage($"use As<{tableName}>(\"{tableName}\")", $"请把 As(\"{tableName}\"), 改成 As<{tableName}实体>(\"{tableName}\")")); - } - else - { - this.QueryBuilder.AsTables.Add(entityName, tableName); - } - return this; - } - protected void _Filter(string FilterName, bool isDisabledGobalFilter) - { - QueryBuilder.IsDisabledGobalFilter = isDisabledGobalFilter; - if (this.Context.QueryFilter.GeFilterList.HasValue() && FilterName.HasValue()) - { - var list = this.Context.QueryFilter.GeFilterList.Where(it => it.FilterName == FilterName && it.IsJoinQuery == !QueryBuilder.IsSingle()); - foreach (var item in list) - { - var filterResult = item.FilterValue(this.Context); - Where(filterResult.Sql + UtilConstants.Space, filterResult.Parameters); - } - } - } - public ISugarQueryable _PartitionBy(Expression expression) - { - QueryBuilder.CheckExpression(expression, "PartitionBy"); - LambdaExpression lambda = expression as LambdaExpression; - expression = lambda.Body; - var isSingle = QueryBuilder.IsSingle(); - ExpressionResult lamResult = null; - string result = null; - if (expression is NewExpression) - { - lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.ArraySingle : ResolveExpressType.ArrayMultiple); - result = string.Join(",", lamResult.GetResultArray()); - } - else - { - lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); - result = lamResult.GetResultString(); - } - PartitionBy(result); - return this; - } - protected ISugarQueryable _Having(Expression expression) - { - QueryBuilder.CheckExpression(expression, "Having"); - var isSingle = QueryBuilder.IsSingle(); - var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.WhereSingle : ResolveExpressType.WhereMultiple); - Having(lamResult.GetResultString()); - return this; - } - protected List _ToList() - { - List result = null; - var sqlObj = this._ToSql(); - if (IsCache) - { - var cacheService = this.Context.CurrentConnectionConfig.ConfigureExternalServices.DataInfoCacheService; - result = CacheSchemeMain.GetOrCreate>(cacheService, this.QueryBuilder, () => { return GetData(sqlObj); }, CacheTime, this.Context,CacheKey); - } - else - { - result = GetData(sqlObj); - } - RestoreMapping(); - _Mapper(result); - _InitNavigat(result); - return result; - } - private async Task _InitNavigatAsync(List result) - { - if (this.QueryBuilder.Includes != null) - { - await Task.Run(() => { _InitNavigat(result); }); - } - } - - private void _InitNavigat(List result) - { - if (this.QueryBuilder.Includes != null) - { - var managers=(this.QueryBuilder.Includes as List); - if (this.QueryBuilder.SelectValue.HasValue()&& this.QueryBuilder.NoCheckInclude==false) - { - Check.ExceptionEasy("To use includes, use select after tolist()", "使用Includes请在ToList()之后在使用Select"); - } - foreach (var it in managers) - { - var manager = it as NavigatManager; - manager.RootList = result; - manager.Execute(); - } - } - } - - protected async Task> _ToListAsync() - { - List result = null; - var sqlObj = this._ToSql(); - if (IsCache) - { - var cacheService = this.Context.CurrentConnectionConfig.ConfigureExternalServices.DataInfoCacheService; - result = CacheSchemeMain.GetOrCreate>(cacheService, this.QueryBuilder, () => { return GetData(sqlObj); }, CacheTime, this.Context,CacheKey); - } - else - { - result =await GetDataAsync(sqlObj); - } - RestoreMapping(); - _Mapper(result); - await _InitNavigatAsync(result); - return result; - } - - protected void _Mapper(List result) - { - if (this.EntityInfo.Columns.Any(it => it.IsTranscoding)) - { - foreach (var item in result) - { - foreach (var column in this.EntityInfo.Columns.Where(it => it.IsTranscoding)) - { - var value = column.PropertyInfo.GetValue(item, null); - if (value != null) - { - column.PropertyInfo.SetValue(item, UtilMethods.DecodeBase64(value.ToString()), null); - } - } - } - } - if (this.Mappers.HasValue()) - { - foreach (var mapper in this.Mappers) - { - if (typeof(TResult) == typeof(T)) - { - mapper(result.Select(it => (T)Convert.ChangeType(it, typeof(T))).ToList()); - } - else - { - Check.Exception(true, "{0} and {1} are not a type, Try .select().mapper().ToList", typeof(TResult).FullName, typeof(T).FullName); - } - } - } - if (this.MapperAction != null) - { - foreach (TResult item in result) - { - if (typeof(TResult) == typeof(T)) - { - foreach (var mapper in this.MapperAction) - { - mapper((T)(item as object)); - } - } - else - { - Check.Exception(true, "{0} and {1} are not a type, Try .select().mapper().ToList", typeof(TResult).FullName, typeof(T).FullName); - } - } - } - if (this.MapperActionWithCache != null) - { - if (typeof(TResult) == typeof(T)) - { - var list = (List)Convert.ChangeType(result, typeof(List)); - var mapperCache = new MapperCache(list, this.Context); - foreach (T item in list) - { - mapperCache.GetIndex = 0; - this.MapperActionWithCache(item, mapperCache); - } - } - else - { - Check.Exception(true, "{0} and {1} are not a type, Try .select().mapper().ToList", typeof(TResult).FullName, typeof(T).FullName); - } - } - } - - private ISugarQueryable _Mapper(Expression mapperObject, Expression mapperField) - { - if ((mapperObject as LambdaExpression).Body is UnaryExpression) - { - mapperObject = ((mapperObject as LambdaExpression).Body as UnaryExpression).Operand; - } - else - { - mapperObject = (mapperObject as LambdaExpression).Body; - } - if ((mapperField as LambdaExpression).Body is UnaryExpression) - { - mapperField = ((mapperField as LambdaExpression).Body as UnaryExpression).Operand; - } - else - { - mapperField = (mapperField as LambdaExpression).Body; - } - Check.Exception(mapperObject is MemberExpression == false || mapperField is MemberExpression == false, ".Mapper() parameter error"); - var mapperObjectExp = mapperObject as MemberExpression; - var mapperFieldExp = mapperField as MemberExpression; - Check.Exception(mapperFieldExp.Type.IsClass(), ".Mapper() parameter error"); - var objType = mapperObjectExp.Type; - var filedType = mapperFieldExp.Expression.Type; - Check.Exception(objType != typeof(TObject) && objType != typeof(List), ".Mapper() parameter error"); - if (objType == typeof(List)) - { - objType = typeof(TObject); - } - var filedName = mapperFieldExp.Member.Name; - var objName = mapperObjectExp.Member.Name; - var filedEntity = this.Context.EntityMaintenance.GetEntityInfo(objType); - var objEntity = this.Context.EntityMaintenance.GetEntityInfo(filedType); - var isSelf = filedType == typeof(T); - if (Mappers == null) - Mappers = new List>>(); - if (isSelf) - { - Action> mapper = (entitys) => - { - if (entitys.IsNullOrEmpty() || !entitys.Any()) return; - var entity = entitys.First(); - var whereCol = filedEntity.Columns.FirstOrDefault(it => it.PropertyName.Equals(filedName, StringComparison.CurrentCultureIgnoreCase)); - if (whereCol == null) - { - whereCol = filedEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true); - } - if (whereCol == null) - { - whereCol = filedEntity.Columns.FirstOrDefault(it => GetPrimaryKeys().Any(pk => pk.Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase))); - } - if (whereCol == null) - { - whereCol = filedEntity.Columns.FirstOrDefault(it => it.PropertyName.Equals("id", StringComparison.CurrentCultureIgnoreCase)); - } - if (whereCol == null) - { - whereCol = filedEntity.Columns.FirstOrDefault(it => (it.PropertyName).Equals(it.EntityName + "id", StringComparison.CurrentCultureIgnoreCase)); - } - if (whereCol == null) - { - Check.Exception(true, ".Mapper() parameter error"); - } - List inValues = entitys.Select(it => it.GetType().GetProperty(filedName).GetValue(it, null).ObjToString()).ToList(); - if (inValues!=null&& inValues.Any()&&UtilMethods.GetUnderType(entitys.First().GetType().GetProperty(filedName).PropertyType) == UtilConstants.GuidType) - { - inValues = inValues.Select(x => x == "" ? "null" : x).Distinct().ToList(); - } - List wheres = new List() - { - new ConditionalModel() - { - FieldName=this.SqlBuilder.GetTranslationColumnName(whereCol.DbColumnName), - ConditionalType= ConditionalType.In, - FieldValue=string.Join(",",inValues.Distinct()), - CSharpTypeName=whereCol.PropertyInfo.PropertyType.Name - } - }; - var list = this.Context.Queryable().Where(wheres).ToList(); - foreach (var item in entitys) - { - var whereValue = item.GetType().GetProperty(filedName).GetValue(item, null); - var setValue = list.Where(x => x.GetType().GetProperty(whereCol.PropertyName).GetValue(x, null).ObjToString() == whereValue.ObjToString()).ToList(); - var setObject = item.GetType().GetProperty(objName); - if (setObject.PropertyType.FullName.IsCollectionsList()) - { - setObject.SetValue(item, setValue.ToList(), null); - } - else - { - setObject.SetValue(item, setValue.FirstOrDefault(), null); - } - } - }; - Mappers.Add(mapper); - } - else - { - Action> mapper = (entitys) => - { - if (entitys.IsNullOrEmpty() || !entitys.Any()) return; - var entity = entitys.First(); - var tEntity = this.Context.EntityMaintenance.GetEntityInfo(); - var whereCol = tEntity.Columns.FirstOrDefault(it => it.PropertyName.Equals(filedName, StringComparison.CurrentCultureIgnoreCase)); - if (whereCol == null) - { - whereCol = tEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true); - } - if (whereCol == null) - { - whereCol = tEntity.Columns.FirstOrDefault(it => GetPrimaryKeys().Any(pk => pk.Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase))); - } - if (whereCol == null) - { - whereCol = tEntity.Columns.FirstOrDefault(it => it.PropertyName.Equals("id", StringComparison.CurrentCultureIgnoreCase)); - } - if (whereCol == null) - { - whereCol = tEntity.Columns.FirstOrDefault(it => (it.PropertyName).Equals(it.EntityName + "id", StringComparison.CurrentCultureIgnoreCase)); - } - if (whereCol == null) - { - Check.Exception(true, ".Mapper() parameter error"); - } - List inValues = entitys.Select(it => it.GetType().GetProperty(whereCol.PropertyName).GetValue(it, null).ObjToString()).ToList(); - var dbColumnName = filedEntity.Columns.FirstOrDefault(it => it.PropertyName == filedName).DbColumnName; - List wheres = new List() - { - new ConditionalModel() - { - FieldName=dbColumnName, - ConditionalType= ConditionalType.In, - FieldValue=string.Join(",",inValues) - } - }; - var list = this.Context.Queryable().Where(wheres).ToList(); - foreach (var item in entitys) - { - var whereValue = item.GetType().GetProperty(whereCol.PropertyName).GetValue(item, null); - var setValue = list.Where(x => x.GetType().GetProperty(filedName).GetValue(x, null).ObjToString() == whereValue.ObjToString()).ToList(); - var setObject = item.GetType().GetProperty(objName); - if (setObject.PropertyType.FullName.IsCollectionsList()) - { - setObject.SetValue(item, setValue.ToList(), null); - } - else - { - setObject.SetValue(item, setValue.FirstOrDefault(), null); - } - } - }; - Mappers.Add(mapper); - } - - return this; - } - - private ISugarQueryable _Mapper(Expression mapperObject, Expression mainField, Expression childField) - { - if ((mapperObject as LambdaExpression).Body is UnaryExpression) - { - mapperObject = ((mapperObject as LambdaExpression).Body as UnaryExpression).Operand; - } - else - { - mapperObject = (mapperObject as LambdaExpression).Body; - } - if ((mainField as LambdaExpression).Body is UnaryExpression) - { - mainField = ((mainField as LambdaExpression).Body as UnaryExpression).Operand; - } - else - { - mainField = (mainField as LambdaExpression).Body; - } - if ((childField as LambdaExpression).Body is UnaryExpression) - { - childField = ((childField as LambdaExpression).Body as UnaryExpression).Operand; - } - else - { - childField = (childField as LambdaExpression).Body; - } - Check.Exception(mapperObject is MemberExpression == false || mainField is MemberExpression == false, ".Mapper() parameter error"); - var mapperObjectExp = mapperObject as MemberExpression; - var mainFieldExp = mainField as MemberExpression; - var childFieldExp = childField as MemberExpression; - Check.Exception(mainFieldExp.Type.IsClass(), ".Mapper() parameter error"); - Check.Exception(childFieldExp.Type.IsClass(), ".Mapper() parameter error"); - var objType = mapperObjectExp.Type; - var filedType = mainFieldExp.Expression.Type; - Check.Exception(objType != typeof(TObject) && objType != typeof(List), ".Mapper() parameter error"); - if (objType == typeof(List)) - { - objType = typeof(TObject); - } - var mainFiledName = mainFieldExp.Member.Name; - var childFiledName = childFieldExp.Member.Name; - var objName = mapperObjectExp.Member.Name; - var filedEntity = this.Context.EntityMaintenance.GetEntityInfo(objType); - var objEntity = this.Context.EntityMaintenance.GetEntityInfo(filedType); - var isSelf = filedType == typeof(T); - if (Mappers == null) - Mappers = new List>>(); - if (isSelf) - { - Action> mapper = (entitys) => - { - if (entitys.IsNullOrEmpty() || !entitys.Any()) return; - var entity = entitys.First(); - var whereCol = filedEntity.Columns.FirstOrDefault(it => it.PropertyName.Equals(childFiledName, StringComparison.CurrentCultureIgnoreCase)); - if (whereCol == null) - { - whereCol = filedEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true); - } - if (whereCol == null) - { - whereCol = filedEntity.Columns.FirstOrDefault(it => GetPrimaryKeys().Any(pk => pk.Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase))); - } - if (whereCol == null) - { - whereCol = filedEntity.Columns.FirstOrDefault(it => it.PropertyName.Equals("id", StringComparison.CurrentCultureIgnoreCase)); - } - if (whereCol == null) - { - whereCol = filedEntity.Columns.FirstOrDefault(it => (it.PropertyName).Equals(it.EntityName + "id", StringComparison.CurrentCultureIgnoreCase)); - } - if (whereCol == null) - { - Check.Exception(true, ".Mapper() parameter error"); - } - List inValues = entitys.Select(it => it.GetType().GetProperty(mainFiledName).GetValue(it, null).ObjToString()).ToList(); - List wheres = new List() - { - new ConditionalModel() - { - FieldName=whereCol.DbColumnName, - ConditionalType= ConditionalType.In, - FieldValue=string.Join(",",inValues.Distinct()) - } - }; - var list = this.Context.Queryable().Where(wheres).ToList(); - foreach (var item in entitys) - { - var whereValue = item.GetType().GetProperty(mainFiledName).GetValue(item, null); - var setValue = list.Where(x => x.GetType().GetProperty(whereCol.PropertyName).GetValue(x, null).ObjToString() == whereValue.ObjToString()).ToList(); - var setObject = item.GetType().GetProperty(objName); - if (setObject.PropertyType.FullName.IsCollectionsList()) - { - setObject.SetValue(item, setValue.ToList(), null); - } - else - { - setObject.SetValue(item, setValue.FirstOrDefault(), null); - } - } - }; - Mappers.Add(mapper); - } - else - { - Action> mapper = (entitys) => - { - if (entitys.IsNullOrEmpty() || !entitys.Any()) return; - var entity = entitys.First(); - var tEntity = this.Context.EntityMaintenance.GetEntityInfo(); - var whereCol = tEntity.Columns.FirstOrDefault(it => it.PropertyName.Equals(childFiledName, StringComparison.CurrentCultureIgnoreCase)); - if (whereCol == null) - { - whereCol = tEntity.Columns.FirstOrDefault(it => it.IsPrimarykey == true); - } - if (whereCol == null) - { - whereCol = tEntity.Columns.FirstOrDefault(it => GetPrimaryKeys().Any(pk => pk.Equals(it.DbColumnName, StringComparison.CurrentCultureIgnoreCase))); - } - if (whereCol == null) - { - whereCol = tEntity.Columns.FirstOrDefault(it => it.PropertyName.Equals("id", StringComparison.CurrentCultureIgnoreCase)); - } - if (whereCol == null) - { - whereCol = tEntity.Columns.FirstOrDefault(it => (it.PropertyName).Equals(it.EntityName + "id", StringComparison.CurrentCultureIgnoreCase)); - } - if (whereCol == null) - { - Check.Exception(true, ".Mapper() parameter error"); - } - List inValues = entitys.Select(it => it.GetType().GetProperty(whereCol.PropertyName).GetValue(it, null).ObjToString()).ToList(); - var dbColumnName = filedEntity.Columns.FirstOrDefault(it => it.PropertyName == mainFiledName).DbColumnName; - List wheres = new List() - { - new ConditionalModel() - { - FieldName=dbColumnName, - ConditionalType= ConditionalType.In, - FieldValue=string.Join(",",inValues) - } - }; - var list = this.Context.Queryable().Where(wheres).ToList(); - foreach (var item in entitys) - { - var whereValue = item.GetType().GetProperty(whereCol.PropertyName).GetValue(item, null); - var setValue = list.Where(x => x.GetType().GetProperty(mainFiledName).GetValue(x, null).ObjToString() == whereValue.ObjToString()).ToList(); - var setObject = item.GetType().GetProperty(objName); - if (setObject.PropertyType.FullName.IsCollectionsList()) - { - setObject.SetValue(item, setValue.ToList(), null); - } - else - { - setObject.SetValue(item, setValue.FirstOrDefault(), null); - } - } - }; - Mappers.Add(mapper); - } - - return this; - } - protected int GetCount() - { - var sql = string.Empty; - ToSqlBefore(); - sql = QueryBuilder.ToSqlString(); - sql = QueryBuilder.ToCountSql(sql); - var result = Context.Ado.GetInt(sql, QueryBuilder.Parameters.ToArray()); - return result; - } - protected async Task 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() - { - var moreSetts = this.Context.CurrentConnectionConfig.MoreSettings; - if (moreSetts != null && moreSetts.IsWithNoLockQuery && string.IsNullOrEmpty(QueryBuilder.TableWithString)) - { - this.With(SqlWith.NoLock); - } - } - - protected List GetData(KeyValuePair> sqlObj) - { - List result; - var isComplexModel = QueryBuilder.IsComplexModel(sqlObj.Key); - var entityType = typeof(TResult); - bool isChangeQueryableSlave = GetIsSlaveQuery(); - bool isChangeQueryableMasterSlave = GetIsMasterQuery(); - var dataReader = this.Db.GetDataReader(sqlObj.Key, sqlObj.Value.ToArray()); - result = GetData(isComplexModel, entityType, dataReader); - RestChangeMasterQuery(isChangeQueryableMasterSlave); - RestChangeSlaveQuery(isChangeQueryableSlave); - return result; - } - - private void RestChangeMasterQuery(bool isChangeQueryableMasterSlave) - { - if (isChangeQueryableMasterSlave) - this.Context.Ado.IsDisableMasterSlaveSeparation = false; - } - - private bool GetIsMasterQuery() - { - var isChangeQueryableMasterSlave = - this.QueryBuilder.IsDisableMasterSlaveSeparation == true && - this.Context.Ado.IsDisableMasterSlaveSeparation == false && - this.Context.Ado.Transaction == null; - if (isChangeQueryableMasterSlave) - this.Context.Ado.IsDisableMasterSlaveSeparation = true; - return isChangeQueryableMasterSlave; - } - - private void RestChangeSlaveQuery(bool isChangeQueryableSlaveSlave) - { - if (isChangeQueryableSlaveSlave) - this.Context.Ado.IsDisableMasterSlaveSeparation = true; - } - - private bool GetIsSlaveQuery() - { - var isChangeQueryableMasterSlave = - this.QueryBuilder.IsEnableMasterSlaveSeparation == true && - this.Context.Ado.IsDisableMasterSlaveSeparation == true && - this.Context.Ado.Transaction == null; - if (isChangeQueryableMasterSlave) - this.Context.Ado.IsDisableMasterSlaveSeparation = false; - return isChangeQueryableMasterSlave; - } - - protected async Task> GetDataAsync(KeyValuePair> sqlObj) - { - List result; - var isComplexModel = QueryBuilder.IsComplexModel(sqlObj.Key); - var entityType = typeof(TResult); - bool isChangeQueryableSlave = GetIsSlaveQuery(); - bool isChangeQueryableMasterSlave = GetIsMasterQuery(); - var dataReader = await this.Db.GetDataReaderAsync(sqlObj.Key, sqlObj.Value.ToArray()); - result =await GetDataAsync(isComplexModel, entityType, dataReader); - RestChangeMasterQuery(isChangeQueryableMasterSlave); - RestChangeSlaveQuery(isChangeQueryableSlave); - return result; - } - - private List GetData(bool isComplexModel, Type entityType, IDataReader dataReader) - { - List result; - if (entityType == UtilConstants.DynamicType) - { - result = this.Context.Utilities.DataReaderToExpandoObjectList(dataReader) as List; - } - else if (entityType == UtilConstants.ObjType) - { - result = this.Context.Utilities.DataReaderToExpandoObjectList(dataReader).Select(it => ((TResult)(object)it)).ToList(); - } - else if (QueryBuilder.IsSelectSingleFiledJson) - { - result= this.Context.Utilities.DataReaderToSelectJsonList(dataReader); - } - else if (entityType.IsAnonymousType() || isComplexModel) - { - result = this.Context.Utilities.DataReaderToList(dataReader); - } - else - { - result = this.Bind.DataReaderToList(entityType, dataReader); - } - SetContextModel(result, entityType); - return result; - } - private async Task> GetDataAsync(bool isComplexModel, Type entityType, IDataReader dataReader) - { - List result; - if (entityType == UtilConstants.DynamicType) - { - result =await this.Context.Utilities.DataReaderToExpandoObjectListAsync(dataReader) as List; - } - else if (entityType == UtilConstants.ObjType) - { - var expObj = await this.Context.Utilities.DataReaderToExpandoObjectListAsync(dataReader); - result = expObj.Select(it => ((TResult)(object)it)).ToList(); - } - else if (QueryBuilder.IsSelectSingleFiledJson) - { - result= await this.Context.Utilities.DataReaderToSelectJsonListAsync(dataReader); - } - else if (entityType.IsAnonymousType() || isComplexModel) - { - result =await this.Context.Utilities.DataReaderToListAsync(dataReader); - } - else - { - result =await this.Bind.DataReaderToListAsync(entityType, dataReader); - } - SetContextModel(result, entityType); - return result; - } - - protected void _InQueryable(Expression expression, KeyValuePair> sqlObj) - { - QueryBuilder.CheckExpression(expression, "In"); - string sql = sqlObj.Key; - if (sqlObj.Value.HasValue()) - { - this.SqlBuilder.RepairReplicationParameters(ref sql, sqlObj.Value.ToArray(), 100); - this.QueryBuilder.Parameters.AddRange(sqlObj.Value); - } - var isSingle = QueryBuilder.IsSingle(); - var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); - var fieldName = lamResult.GetResultString(); - var whereSql = string.Format(this.QueryBuilder.InTemplate, fieldName, sql); - this.QueryBuilder.WhereInfos.Add(SqlBuilder.AppendWhereOrAnd(this.QueryBuilder.WhereInfos.IsNullOrEmpty(), whereSql)); - base._InQueryableIndex += 100; - } - - protected List GetPrimaryKeys() - { - if (this.Context.IsSystemTablesConfig) - { - return this.Context.DbMaintenance.GetPrimaries(this.Context.EntityMaintenance.GetTableName(this.EntityInfo.EntityName)); - } - else - { - return this.EntityInfo.Columns.Where(it => it.IsPrimarykey).Select(it => it.DbColumnName).ToList(); - } - } - protected virtual List GetIdentityKeys() - { - if (this.Context.IsSystemTablesConfig) - { - return this.Context.DbMaintenance.GetIsIdentities(this.EntityInfo.DbTableName); - } - else - { - return this.EntityInfo.Columns.Where(it => it.IsIdentity).Select(it => it.DbColumnName).ToList(); - } - } - - protected void RestoreMapping() - { - if (IsAs && _RestoreMapping) - { - this.Context.MappingTables = OldMappingTableList == null ? new MappingTableList() : OldMappingTableList; - } - } - protected void InitMapping() - { - if (this.QueryableMappingTableList != null) - this.Context.MappingTables = this.QueryableMappingTableList; - } - - private void SetContextModel(List result, Type entityType) - { - if (result.HasValue()) - { - if (UtilMethods.GetRootBaseType(entityType).HasValue() && UtilMethods.GetRootBaseType(entityType) == UtilConstants.ModelType) - { - foreach (var item in result) - { - 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); - } - } - } - } - protected void CopyQueryBuilder(QueryBuilder asyncQueryableBuilder) - { - var pars = new List(); - if (this.QueryBuilder.Parameters != null) - { - pars=this.QueryBuilder.Parameters.Select(it=>new SugarParameter(it.ParameterName,it.Value) { - DbType=it.DbType, - Value=it.Value, - ParameterName=it.ParameterName, - Direction=it.Direction, - IsArray=it.IsArray, - IsJson=it.IsJson, - IsNullable=it.IsNullable, - IsRefCursor=it.IsRefCursor, - Size=it.Size, - SourceColumn=it.SourceColumn, - SourceColumnNullMapping=it.SourceColumnNullMapping, - SourceVersion=it.SourceVersion, - TempDate=it.TempDate, - TypeName=it.TypeName, - UdtTypeName=it.UdtTypeName, - _Size=it._Size - }).ToList(); - } - asyncQueryableBuilder.IsEnableMasterSlaveSeparation = this.QueryBuilder.IsEnableMasterSlaveSeparation; - asyncQueryableBuilder.TranLock = this.QueryBuilder.TranLock; - asyncQueryableBuilder.IsDisableMasterSlaveSeparation = this.QueryBuilder.IsDisableMasterSlaveSeparation; - asyncQueryableBuilder.IsQueryInQuery = this.QueryBuilder.IsQueryInQuery; - asyncQueryableBuilder.Includes = this.QueryBuilder.Includes; - asyncQueryableBuilder.Take = this.QueryBuilder.Take; - asyncQueryableBuilder.Skip = this.QueryBuilder.Skip; - asyncQueryableBuilder.SelectValue = this.QueryBuilder.SelectValue; - asyncQueryableBuilder.WhereInfos = this.Context.Utilities.TranslateCopy(this.QueryBuilder.WhereInfos); - asyncQueryableBuilder.EasyJoinInfos = this.Context.Utilities.TranslateCopy(this.QueryBuilder.EasyJoinInfos); - asyncQueryableBuilder.JoinQueryInfos = this.Context.Utilities.TranslateCopy(this.QueryBuilder.JoinQueryInfos); - asyncQueryableBuilder.WhereIndex = this.QueryBuilder.WhereIndex; - asyncQueryableBuilder.EntityType = this.QueryBuilder.EntityType; - asyncQueryableBuilder.EntityName = this.QueryBuilder.EntityName; - asyncQueryableBuilder.Parameters = pars; - asyncQueryableBuilder.TableShortName = this.QueryBuilder.TableShortName; - asyncQueryableBuilder.TableWithString = this.QueryBuilder.TableWithString; - asyncQueryableBuilder.GroupByValue = this.QueryBuilder.GroupByValue; - asyncQueryableBuilder.IsDistinct = this.QueryBuilder.IsDistinct; - asyncQueryableBuilder.OrderByValue = this.QueryBuilder.OrderByValue; - asyncQueryableBuilder.IsDisabledGobalFilter = this.QueryBuilder.IsDisabledGobalFilter; - asyncQueryableBuilder.PartitionByValue = this.QueryBuilder.PartitionByValue; - asyncQueryableBuilder.JoinExpression = this.QueryBuilder.JoinExpression; - asyncQueryableBuilder.WhereIndex = this.QueryBuilder.WhereIndex; - asyncQueryableBuilder.HavingInfos = this.QueryBuilder.HavingInfos; - asyncQueryableBuilder.LambdaExpressions.ParameterIndex = this.QueryBuilder.LambdaExpressions.ParameterIndex; - asyncQueryableBuilder.IgnoreColumns = this.Context.Utilities.TranslateCopy(this.QueryBuilder.IgnoreColumns); - asyncQueryableBuilder.AsTables = this.Context.Utilities.TranslateCopy(this.QueryBuilder.AsTables); - asyncQueryableBuilder.DisableTop = this.QueryBuilder.DisableTop; - asyncQueryableBuilder.Offset = this.QueryBuilder.Offset; - asyncQueryableBuilder.IsSqlQuery = this.QueryBuilder.IsSqlQuery; - asyncQueryableBuilder.IsSqlQuerySelect = this.QueryBuilder.IsSqlQuerySelect; - asyncQueryableBuilder.OldSql = this.QueryBuilder.OldSql; - asyncQueryableBuilder.IsCrossQueryWithAttr = this.QueryBuilder.IsCrossQueryWithAttr; - asyncQueryableBuilder.CrossQueryItems = this.QueryBuilder.CrossQueryItems; - } - protected int SetCacheTime(int cacheDurationInSeconds) - { - if (cacheDurationInSeconds == int.MaxValue && this.Context.CurrentConnectionConfig.MoreSettings != null && this.Context.CurrentConnectionConfig.MoreSettings.DefaultCacheDurationInSeconds > 0) - { - cacheDurationInSeconds = this.Context.CurrentConnectionConfig.MoreSettings.DefaultCacheDurationInSeconds; - } - - return cacheDurationInSeconds; - } - - #endregion - } - #endregion - #region T2 - public partial class QueryableProvider : QueryableProvider, ISugarQueryable - { - 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; - } - #region Where - public new 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 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 Where(List conditionalModels) - { - base.Where(conditionalModels); - return this; - } - public new ISugarQueryable Where(IFuncModel funcModel) - { - var obj = this.SqlBuilder.FuncModelToSql(funcModel); - return this.Where(obj.Key, obj.Value); - } - public new ISugarQueryable WhereIF(bool isWhere, string whereString, object whereObj) - { - if (!isWhere) return this; - this.Where(whereString, whereObj); - return this; - } - /// - /// if a property that is not empty is a condition - /// - /// - /// - public new ISugarQueryable WhereClass(ClassType whereClass, bool ignoreDefaultValue = false) where ClassType : class, new() - { - base.WhereClass(whereClass, ignoreDefaultValue); - return this; - } - /// - /// if a property that is not empty is a condition - /// - /// - /// - public new ISugarQueryable WhereClass(List whereClassTypes, bool ignoreDefaultValue = false) where ClassType : class, new() - { - - base.WhereClass(whereClassTypes, ignoreDefaultValue); - return this; - } - #endregion - - #region Select - public ISugarQueryable Select(Expression> expression) - { - return _Select(expression); - } - - #endregion - - #region Order - public new ISugarQueryable OrderBy(string orderFileds) - { - base.OrderBy(orderFileds); - return this; - } - public ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc) - { - _OrderBy(expression, type); - return this; - } - public new virtual ISugarQueryable OrderByDescending(Expression> expression) - { - this._OrderBy(expression, OrderByType.Desc); - return this; - } - public virtual ISugarQueryable OrderByDescending(Expression> expression) - { - this._OrderBy(expression, OrderByType.Desc); - return this; - } - public new ISugarQueryable OrderBy(Expression> expression, OrderByType type) - { - _OrderBy(expression, type); - return this; - } - public new ISugarQueryable OrderByIF(bool isOrderBy, string orderFileds) - { - if (isOrderBy) - base.OrderBy(orderFileds); - 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; - } - #endregion - - #region GroupBy - public new virtual ISugarQueryable GroupByIF(bool isGroupBy, Expression> expression) - { - if (isGroupBy) - { - GroupBy(expression); - } - return this; - } - public virtual ISugarQueryable GroupByIF(bool isGroupBy, Expression> expression) - { - if (isGroupBy) - { - GroupBy(expression); - } - return this; - } - public new virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) - { - if (isHaving) - this._Having(expression); - return this; - } - public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) - { - if (isHaving) - this._Having(expression); - return this; - } - public new ISugarQueryable GroupBy(Expression> expression) - { - _GroupBy(expression); - return this; - } - - public ISugarQueryable GroupBy(Expression> expression) - { - _GroupBy(expression); - return this; - } - - public new ISugarQueryable Having(Expression> expression) - { - this._Having(expression); - return this; - } - - public ISugarQueryable Having(Expression> expression) - { - this._Having(expression); - return this; - } - - public new ISugarQueryable Having(string whereString, object whereObj) - { - base.Having(whereString, whereObj); - 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); - } - public Task MaxAsync(Expression> expression) - { - return _MaxAsync(expression); - } - public Task MinAsync(Expression> expression) - { - return _MinAsync(expression); - } - public Task SumAsync(Expression> expression) - { - return _SumAsync(expression); - } - public Task AvgAsync(Expression> expression) - { - return _AvgAsync(expression); - } - #endregion - - #region In - public new ISugarQueryable InIF(bool isIn, params TParamter[] pkValues) - { - if (isIn) - { - In(pkValues); - } - return this; - } - public new ISugarQueryable In(Expression> expression, params FieldType[] inValues) - { - QueryBuilder.CheckExpression(expression, "In"); - 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) - { - QueryBuilder.CheckExpression(expression, "In"); - 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; - } - - public ISugarQueryable In(Expression> expression, params FieldType[] inValues) - { - QueryBuilder.CheckExpression(expression, "In"); - var isSingle = QueryBuilder.IsSingle(); - var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); - var fieldName = lamResult.GetResultString(); - In(fieldName, inValues); - return this; - } - public ISugarQueryable In(Expression> expression, List inValues) - { - QueryBuilder.CheckExpression(expression, "In"); - var isSingle = QueryBuilder.IsSingle(); - var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); - var fieldName = lamResult.GetResultString(); - In(fieldName, inValues); - return this; - } - public ISugarQueryable In(Expression> expression, ISugarQueryable childQueryExpression) - { - var sqlObj = childQueryExpression.ToSql(); - _InQueryable(expression, sqlObj); - return this; - } - #endregion - - #region Other - public new ISugarQueryable Clone() - { - var queryable = this.Context.Queryable((t, t2) => 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 Filter(string FilterName, bool isDisabledGobalFilter = false) - { - _Filter(FilterName, isDisabledGobalFilter); - 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; - } - - public bool Any(Expression> expression) - { - _Where(expression); - var result = Any(); - this.QueryBuilder.WhereInfos.Remove(this.QueryBuilder.WhereInfos.Last()); - return result; - } - public new ISugarQueryable Distinct() - { - QueryBuilder.IsDistinct = true; - return this; - } - - public new ISugarQueryable Take(int num) - { - QueryBuilder.Take = num; - return this; - } - #endregion - } - #endregion - #region T3 - public partial class QueryableProvider : QueryableProvider, ISugarQueryable - { - 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; - } - - #region Group - public new virtual ISugarQueryable GroupByIF(bool isGroupBy, Expression> expression) - { - if (isGroupBy) - { - GroupBy(expression); - } - return this; - } - public virtual ISugarQueryable GroupByIF(bool isGroupBy, Expression> expression) - { - if (isGroupBy) - { - GroupBy(expression); - } - return this; - } - public virtual ISugarQueryable GroupByIF(bool isGroupBy, Expression> expression) - { - if (isGroupBy) - { - GroupBy(expression); - } - return this; - } - public ISugarQueryable GroupBy(Expression> expression) - { - _GroupBy(expression); - return this; - } - - public ISugarQueryable GroupBy(Expression> expression) - { - _GroupBy(expression); - return this; - } - public new ISugarQueryable GroupBy(Expression> expression) - { - _GroupBy(expression); - return this; - } - - public new ISugarQueryable Having(Expression> expression) - { - this._Having(expression); - return this; - } - - public ISugarQueryable Having(Expression> expression) - { - this._Having(expression); - return this; - } - - public ISugarQueryable Having(Expression> expression) - { - this._Having(expression); - return this; - } - - public new ISugarQueryable Having(string whereString, object whereObj) - { - base.Having(whereString, whereObj); - return this; - } - public new virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) - { - if (isHaving) - this._Having(expression); - return this; - } - public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) - { - if (isHaving) - this._Having(expression); - return this; - } - public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) - { - if (isHaving) - this._Having(expression); - return this; - } - #endregion - - #region Order - public new virtual ISugarQueryable OrderByDescending(Expression> expression) - { - this._OrderBy(expression, OrderByType.Desc); - return this; - } - public virtual ISugarQueryable OrderByDescending(Expression> expression) - { - this._OrderBy(expression, OrderByType.Desc); - return this; - } - public virtual ISugarQueryable OrderByDescending(Expression> expression) - { - this._OrderBy(expression, OrderByType.Desc); - return this; - } - public new ISugarQueryable OrderBy(string orderFileds) - { - base.OrderBy(orderFileds); - 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 OrderBy(Expression> expression, OrderByType type) - { - _OrderBy(expression, type); - return this; - } - public new ISugarQueryable OrderByIF(bool isOrderBy, string orderFileds) - { - if (isOrderBy) - base.OrderBy(orderFileds); - 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; - } - #endregion - - #region Select - public ISugarQueryable Select(Expression> expression) - { - return _Select(expression); - } - - public ISugarQueryable Select(Expression> expression) - { - return _Select(expression); - } - - public ISugarQueryable Where(Expression> expression) - { - _Where(expression); - return this; - } - #endregion - - #region Where - public ISugarQueryable Where(Expression> expression) - { - _Where(expression); - return this; - } - - public new ISugarQueryable Where(Expression> expression) - { - _Where(expression); - return this; - } - public new ISugarQueryable Where(List conditionalModels) - { - base.Where(conditionalModels); - return this; - } - public new ISugarQueryable Where(IFuncModel funcModel) - { - var obj = this.SqlBuilder.FuncModelToSql(funcModel); - return this.Where(obj.Key, obj.Value); - } - 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 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; - } - /// - /// if a property that is not empty is a condition - /// - /// - /// - public new ISugarQueryable WhereClass(ClassType whereClass, bool ignoreDefaultValue = false) where ClassType : class, new() - { - base.WhereClass(whereClass, ignoreDefaultValue); - return this; - } - /// - /// if a property that is not empty is a condition - /// - /// - /// - public new ISugarQueryable WhereClass(List whereClassTypes, bool ignoreDefaultValue = false) where ClassType : class, new() - { - - base.WhereClass(whereClassTypes, ignoreDefaultValue); - 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); - } - public Task MaxAsync(Expression> expression) - { - return _MaxAsync(expression); - } - public Task MinAsync(Expression> expression) - { - return _MinAsync(expression); - } - public Task SumAsync(Expression> expression) - { - return _SumAsync(expression); - } - public Task AvgAsync(Expression> expression) - { - return _AvgAsync(expression); - } - #endregion - - #region In - public new ISugarQueryable InIF(bool isIn, params TParamter[] pkValues) - { - if (isIn) - { - In(pkValues); - } - return this; - } - public new ISugarQueryable In(Expression> expression, params FieldType[] inValues) - { - QueryBuilder.CheckExpression(expression, "In"); - 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) - { - QueryBuilder.CheckExpression(expression, "In"); - 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; - } - - public ISugarQueryable In(Expression> expression, params FieldType[] inValues) - { - QueryBuilder.CheckExpression(expression, "In"); - var isSingle = QueryBuilder.IsSingle(); - var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); - var fieldName = lamResult.GetResultString(); - In(fieldName, inValues); - return this; - } - public ISugarQueryable In(Expression> expression, List inValues) - { - QueryBuilder.CheckExpression(expression, "In"); - var isSingle = QueryBuilder.IsSingle(); - var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); - var fieldName = lamResult.GetResultString(); - In(fieldName, inValues); - return this; - } - public ISugarQueryable In(Expression> expression, ISugarQueryable childQueryExpression) - { - var sqlObj = childQueryExpression.ToSql(); - _InQueryable(expression, sqlObj); - return this; - } - - public ISugarQueryable In(Expression> expression, params FieldType[] inValues) - { - QueryBuilder.CheckExpression(expression, "In"); - var isSingle = QueryBuilder.IsSingle(); - var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); - var fieldName = lamResult.GetResultString(); - In(fieldName, inValues); - return this; - } - public ISugarQueryable In(Expression> expression, List inValues) - { - QueryBuilder.CheckExpression(expression, "In"); - var isSingle = QueryBuilder.IsSingle(); - var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); - var fieldName = lamResult.GetResultString(); - In(fieldName, inValues); - return this; - } - public ISugarQueryable In(Expression> expression, ISugarQueryable childQueryExpression) - { - var sqlObj = childQueryExpression.ToSql(); - _InQueryable(expression, sqlObj); - return this; - } - #endregion - - #region Other - public new ISugarQueryable Take(int num) - { - QueryBuilder.Take = num; - return this; - } - public new ISugarQueryable Clone() - { - var queryable = this.Context.Queryable((t, t2, t3) => 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 Filter(string FilterName, bool isDisabledGobalFilter = false) - { - _Filter(FilterName, isDisabledGobalFilter); - 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; - } - - public bool Any(Expression> expression) - { - _Where(expression); - var result = Any(); - this.QueryBuilder.WhereInfos.Remove(this.QueryBuilder.WhereInfos.Last()); - return result; - } - public new ISugarQueryable Distinct() - { - QueryBuilder.IsDistinct = true; - return this; - } - #endregion - } - #endregion - #region T4 - public partial class QueryableProvider : QueryableProvider, ISugarQueryable - { - 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; - } - - #region Where - 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 new ISugarQueryable Where(List conditionalModels) - { - base.Where(conditionalModels); - return this; - } - public new ISugarQueryable Where(IFuncModel funcModel) - { - var obj = this.SqlBuilder.FuncModelToSql(funcModel); - return this.Where(obj.Key, obj.Value); - } - 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 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; - } - /// - /// if a property that is not empty is a condition - /// - /// - /// - public new ISugarQueryable WhereClass(ClassType whereClass, bool ignoreDefaultValue = false) where ClassType : class, new() - { - base.WhereClass(whereClass, ignoreDefaultValue); - return this; - } - /// - /// if a property that is not empty is a condition - /// - /// - /// - public new ISugarQueryable WhereClass(List whereClassTypes, bool ignoreDefaultValue = false) where ClassType : class, new() - { - - base.WhereClass(whereClassTypes, ignoreDefaultValue); - return this; - } - #endregion - - #region Select - 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 virtual ISugarQueryable OrderByDescending(Expression> expression) - { - this._OrderBy(expression, OrderByType.Desc); - return this; - } - public virtual ISugarQueryable OrderByDescending(Expression> expression) - { - this._OrderBy(expression, OrderByType.Desc); - return this; - } - public virtual ISugarQueryable OrderByDescending(Expression> expression) - { - this._OrderBy(expression, OrderByType.Desc); - return this; - } - public virtual ISugarQueryable OrderByDescending(Expression> expression) - { - this._OrderBy(expression, OrderByType.Desc); - return this; - } - public new ISugarQueryable OrderBy(string orderFileds) - { - base.OrderBy(orderFileds); - 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 new ISugarQueryable OrderByIF(bool isOrderBy, string orderFileds) - { - if (isOrderBy) - base.OrderBy(orderFileds); - 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; - } - #endregion - - #region GroupBy - public new virtual ISugarQueryable GroupByIF(bool isGroupBy, Expression> expression) - { - if (isGroupBy) - { - GroupBy(expression); - } - return this; - } - public virtual ISugarQueryable GroupByIF(bool isGroupBy, Expression> expression) - { - if (isGroupBy) - { - GroupBy(expression); - } - return this; - } - public virtual ISugarQueryable GroupByIF(bool isGroupBy, Expression> expression) - { - if (isGroupBy) - { - GroupBy(expression); - } - return this; - } - public virtual ISugarQueryable GroupByIF(bool isGroupBy, Expression> expression) - { - if (isGroupBy) - { - GroupBy(expression); - } - return this; - } - 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 new ISugarQueryable Having(Expression> expression) - { - this._Having(expression); - return this; - } - - public ISugarQueryable Having(Expression> expression) - { - this._Having(expression); - return this; - } - - public ISugarQueryable Having(Expression> expression) - { - this._Having(expression); - return this; - } - - public ISugarQueryable Having(Expression> expression) - { - this._Having(expression); - return this; - } - - public new ISugarQueryable Having(string whereString, object whereObj) - { - base.Having(whereString, whereObj); - return this; - } - - public new virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) - { - if (isHaving) - this._Having(expression); - return this; - } - public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) - { - if (isHaving) - this._Having(expression); - return this; - } - public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) - { - if (isHaving) - this._Having(expression); - return this; - } - public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) - { - if (isHaving) - this._Having(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 InIF(bool isIn, params TParamter[] pkValues) - { - if (isIn) - { - In(pkValues); - } - return this; - } - public new ISugarQueryable In(Expression> expression, params FieldType[] inValues) - { - QueryBuilder.CheckExpression(expression, "In"); - 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) - { - QueryBuilder.CheckExpression(expression, "In"); - 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; - } - - public ISugarQueryable In(Expression> expression, params FieldType[] inValues) - { - QueryBuilder.CheckExpression(expression, "In"); - var isSingle = QueryBuilder.IsSingle(); - var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); - var fieldName = lamResult.GetResultString(); - In(fieldName, inValues); - return this; - } - public ISugarQueryable In(Expression> expression, List inValues) - { - QueryBuilder.CheckExpression(expression, "In"); - var isSingle = QueryBuilder.IsSingle(); - var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); - var fieldName = lamResult.GetResultString(); - In(fieldName, inValues); - return this; - } - public ISugarQueryable In(Expression> expression, ISugarQueryable childQueryExpression) - { - var sqlObj = childQueryExpression.ToSql(); - _InQueryable(expression, sqlObj); - return this; - } - - public ISugarQueryable In(Expression> expression, params FieldType[] inValues) - { - QueryBuilder.CheckExpression(expression, "In"); - var isSingle = QueryBuilder.IsSingle(); - var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); - var fieldName = lamResult.GetResultString(); - In(fieldName, inValues); - return this; - } - public ISugarQueryable In(Expression> expression, List inValues) - { - QueryBuilder.CheckExpression(expression, "In"); - var isSingle = QueryBuilder.IsSingle(); - var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); - var fieldName = lamResult.GetResultString(); - In(fieldName, inValues); - return this; - } - public ISugarQueryable In(Expression> expression, ISugarQueryable childQueryExpression) - { - var sqlObj = childQueryExpression.ToSql(); - _InQueryable(expression, sqlObj); - return this; - } - - public ISugarQueryable In(Expression> expression, params FieldType[] inValues) - { - QueryBuilder.CheckExpression(expression, "In"); - var isSingle = QueryBuilder.IsSingle(); - var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); - var fieldName = lamResult.GetResultString(); - In(fieldName, inValues); - return this; - } - public ISugarQueryable In(Expression> expression, List inValues) - { - QueryBuilder.CheckExpression(expression, "In"); - var isSingle = QueryBuilder.IsSingle(); - var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); - var fieldName = lamResult.GetResultString(); - In(fieldName, inValues); - return this; - } - public ISugarQueryable In(Expression> expression, ISugarQueryable childQueryExpression) - { - var sqlObj = childQueryExpression.ToSql(); - _InQueryable(expression, sqlObj); - return this; - } - #endregion - - - #region Other - public new ISugarQueryable Take(int num) - { - QueryBuilder.Take = num; - return this; - } - public new ISugarQueryable Clone() - { - var queryable = this.Context.Queryable((t, t2, t3, t4) => 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 Filter(string FilterName, bool isDisabledGobalFilter = false) - { - _Filter(FilterName, isDisabledGobalFilter); - 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; - } - - public bool Any(Expression> expression) - { - _Where(expression); - var result = Any(); - this.QueryBuilder.WhereInfos.Remove(this.QueryBuilder.WhereInfos.Last()); - return result; - } - public new ISugarQueryable Distinct() - { - QueryBuilder.IsDistinct = true; - return this; - } - #endregion - } - #endregion - #region T5 - public partial class QueryableProvider : QueryableProvider, ISugarQueryable - { - 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; - } - - #region Where - 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 new ISugarQueryable Where(List conditionalModels) - { - base.Where(conditionalModels); - return this; - } - public new ISugarQueryable Where(IFuncModel funcModel) - { - var obj = this.SqlBuilder.FuncModelToSql(funcModel); - return this.Where(obj.Key, obj.Value); - } - 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 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; - } - - /// - /// if a property that is not empty is a condition - /// - /// - /// - public new ISugarQueryable WhereClass(ClassType whereClass, bool ignoreDefaultValue = false) where ClassType : class, new() - { - base.WhereClass(whereClass, ignoreDefaultValue); - return this; - } - /// - /// if a property that is not empty is a condition - /// - /// - /// - public new ISugarQueryable WhereClass(List whereClassTypes, bool ignoreDefaultValue = false) where ClassType : class, new() - { - - base.WhereClass(whereClassTypes, ignoreDefaultValue); - return this; - } - - #endregion - - #region Select - 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 virtual ISugarQueryable OrderByDescending(Expression> expression) - { - this._OrderBy(expression, OrderByType.Desc); - return this; - } - public virtual ISugarQueryable OrderByDescending(Expression> expression) - { - this._OrderBy(expression, OrderByType.Desc); - return this; - } - public virtual ISugarQueryable OrderByDescending(Expression> expression) - { - this._OrderBy(expression, OrderByType.Desc); - return this; - } - public virtual ISugarQueryable OrderByDescending(Expression> expression) - { - this._OrderBy(expression, OrderByType.Desc); - return this; - } - public virtual ISugarQueryable OrderByDescending(Expression> expression) - { - this._OrderBy(expression, OrderByType.Desc); - return this; - } - public new ISugarQueryable OrderBy(string orderFileds) - { - base.OrderBy(orderFileds); - 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 new ISugarQueryable OrderByIF(bool isOrderBy, string orderFileds) - { - if (isOrderBy) - base.OrderBy(orderFileds); - 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; - } - #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 new ISugarQueryable Having(Expression> expression) - { - this._Having(expression); - return this; - } - - public ISugarQueryable Having(Expression> expression) - { - this._Having(expression); - return this; - } - - public ISugarQueryable Having(Expression> expression) - { - this._Having(expression); - return this; - } - - public ISugarQueryable Having(Expression> expression) - { - this._Having(expression); - return this; - } - - public ISugarQueryable Having(Expression> expression) - { - this._Having(expression); - return this; - } - - public new ISugarQueryable Having(string whereString, object whereObj) - { - base.Having(whereString, whereObj); - return this; - } - - public new virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) - { - if (isHaving) - this._Having(expression); - return this; - } - public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) - { - if (isHaving) - this._Having(expression); - return this; - } - public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) - { - if (isHaving) - this._Having(expression); - return this; - } - public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) - { - if (isHaving) - this._Having(expression); - return this; - } - public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) - { - if (isHaving) - this._Having(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 Take(int num) - { - QueryBuilder.Take = num; - return this; - } - public new ISugarQueryable Clone() - { - var queryable = this.Context.Queryable((t, t2, t3, t4, t5) => 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 Filter(string FilterName, bool isDisabledGobalFilter = false) - { - _Filter(FilterName, isDisabledGobalFilter); - 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; - } - - public bool Any(Expression> expression) - { - _Where(expression); - var result = Any(); - this.QueryBuilder.WhereInfos.Remove(this.QueryBuilder.WhereInfos.Last()); - return result; - } - public new ISugarQueryable Distinct() - { - QueryBuilder.IsDistinct = true; - return this; - } - #endregion - } - #endregion - #region T6 - public partial class QueryableProvider : QueryableProvider, ISugarQueryable - { - 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; - } - #region Where - 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 new ISugarQueryable Where(List conditionalModels) - { - base.Where(conditionalModels); - return this; - } - public new ISugarQueryable Where(IFuncModel funcModel) - { - var obj = this.SqlBuilder.FuncModelToSql(funcModel); - return this.Where(obj.Key, obj.Value); - } - 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 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; - } - - /// - /// if a property that is not empty is a condition - /// - /// - /// - public new ISugarQueryable WhereClass(ClassType whereClass, bool ignoreDefaultValue = false) where ClassType : class, new() - { - base.WhereClass(whereClass, ignoreDefaultValue); - return this; - } - /// - /// if a property that is not empty is a condition - /// - /// - /// - public new ISugarQueryable WhereClass(List whereClassTypes, bool ignoreDefaultValue = false) where ClassType : class, new() - { - - base.WhereClass(whereClassTypes, ignoreDefaultValue); - return this; - } - #endregion - - #region Select - 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 virtual ISugarQueryable OrderByDescending(Expression> expression) - { - this._OrderBy(expression, OrderByType.Desc); - return this; - } - public virtual ISugarQueryable OrderByDescending(Expression> expression) - { - this._OrderBy(expression, OrderByType.Desc); - return this; - } - public virtual ISugarQueryable OrderByDescending(Expression> expression) - { - this._OrderBy(expression, OrderByType.Desc); - return this; - } - public virtual ISugarQueryable OrderByDescending(Expression> expression) - { - this._OrderBy(expression, OrderByType.Desc); - return this; - } - public virtual ISugarQueryable OrderByDescending(Expression> expression) - { - this._OrderBy(expression, OrderByType.Desc); - return this; - } - public virtual ISugarQueryable OrderByDescending(Expression> expression) - { - this._OrderBy(expression, OrderByType.Desc); - return this; - } - - public new ISugarQueryable OrderBy(string orderFileds) - { - base.OrderBy(orderFileds); - 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 new ISugarQueryable OrderByIF(bool isOrderBy, string orderFileds) - { - if (isOrderBy) - base.OrderBy(orderFileds); - 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; - } - #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 new ISugarQueryable Having(Expression> expression) - { - this._Having(expression); - return this; - } - - public ISugarQueryable Having(Expression> expression) - { - this._Having(expression); - return this; - } - - public ISugarQueryable Having(Expression> expression) - { - this._Having(expression); - return this; - } - - public ISugarQueryable Having(Expression> expression) - { - this._Having(expression); - return this; - } - - public ISugarQueryable Having(Expression> expression) - { - this._Having(expression); - return this; - } - public ISugarQueryable Having(Expression> expression) - { - this._Having(expression); - return this; - } - - public new ISugarQueryable Having(string whereString, object whereObj) - { - base.Having(whereString, whereObj); - return this; - } - - public new virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) - { - if (isHaving) - this._Having(expression); - return this; - } - public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) - { - if (isHaving) - this._Having(expression); - return this; - } - public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) - { - if (isHaving) - this._Having(expression); - return this; - } - public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) - { - if (isHaving) - this._Having(expression); - return this; - } - public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) - { - if (isHaving) - this._Having(expression); - return this; - } - public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) - { - if (isHaving) - this._Having(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 Take(int num) - { - QueryBuilder.Take = num; - return this; - } - public new ISugarQueryable Clone() - { - var queryable = this.Context.Queryable((t, t2, t3, t4, t5, T6) => 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 Filter(string FilterName, bool isDisabledGobalFilter = false) - { - _Filter(FilterName, isDisabledGobalFilter); - 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; - } - - public bool Any(Expression> expression) - { - _Where(expression); - var result = Any(); - this.QueryBuilder.WhereInfos.Remove(this.QueryBuilder.WhereInfos.Last()); - return result; - } - public new ISugarQueryable Distinct() - { - QueryBuilder.IsDistinct = true; - return this; - } - #endregion - } - #endregion - #region T7 - public partial class QueryableProvider : QueryableProvider, ISugarQueryable - { - 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; - } - #region Where - 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 new ISugarQueryable Where(List conditionalModels) - { - base.Where(conditionalModels); - 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 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; - } - /// - /// if a property that is not empty is a condition - /// - /// - /// - public new ISugarQueryable WhereClass(ClassType whereClass, bool ignoreDefaultValue = false) where ClassType : class, new() - { - base.WhereClass(whereClass, ignoreDefaultValue); - return this; - } - /// - /// if a property that is not empty is a condition - /// - /// - /// - public new ISugarQueryable WhereClass(List whereClassTypes, bool ignoreDefaultValue = false) where ClassType : class, new() - { - - base.WhereClass(whereClassTypes, ignoreDefaultValue); - return this; - } - #endregion - - #region Select - 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(string orderFileds) - { - base.OrderBy(orderFileds); - 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; - } - #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 new ISugarQueryable OrderByIF(bool isOrderBy, string orderFileds) - { - if (isOrderBy) - base.OrderBy(orderFileds); - 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 new virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) - { - if (isHaving) - this._Having(expression); - return this; - } - public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) - { - if (isHaving) - this._Having(expression); - return this; - } - public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) - { - if (isHaving) - this._Having(expression); - return this; - } - public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) - { - if (isHaving) - this._Having(expression); - return this; - } - public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) - { - if (isHaving) - this._Having(expression); - return this; - } - public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) - { - if (isHaving) - this._Having(expression); - return this; - } - public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) - { - if (isHaving) - this._Having(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 Take(int num) - { - QueryBuilder.Take = num; - return this; - } - public new ISugarQueryable Clone() - { - var queryable = this.Context.Queryable((t, t2, t3, t4, t5, T6, t7) => 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 Filter(string FilterName, bool isDisabledGobalFilter = false) - { - _Filter(FilterName, isDisabledGobalFilter); - 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; - } - - public bool Any(Expression> expression) - { - _Where(expression); - var result = Any(); - this.QueryBuilder.WhereInfos.Remove(this.QueryBuilder.WhereInfos.Last()); - return result; - } - public new ISugarQueryable Distinct() - { - QueryBuilder.IsDistinct = true; - return this; - } - #endregion - } - #endregion - #region T8 - public partial class QueryableProvider : QueryableProvider, ISugarQueryable - { - 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; - } - #region Where - 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 new ISugarQueryable Where(List conditionalModels) - { - base.Where(conditionalModels); - 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 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; - } - /// - /// if a property that is not empty is a condition - /// - /// - /// - public new ISugarQueryable WhereClass(ClassType whereClass, bool ignoreDefaultValue = false) where ClassType : class, new() - { - base.WhereClass(whereClass, ignoreDefaultValue); - return this; - } - /// - /// if a property that is not empty is a condition - /// - /// - /// - public new ISugarQueryable WhereClass(List whereClassTypes, bool ignoreDefaultValue = false) where ClassType : class, new() - { - - base.WhereClass(whereClassTypes, ignoreDefaultValue); - return this; - } - #endregion - - #region Select - 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(string orderFileds) - { - base.OrderBy(orderFileds); - 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 new ISugarQueryable OrderByIF(bool isOrderBy, string orderFileds) - { - if (isOrderBy) - base.OrderBy(orderFileds); - 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; - } - #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; - } - - #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 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) => 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 Filter(string FilterName, bool isDisabledGobalFilter = false) - { - _Filter(FilterName, isDisabledGobalFilter); - 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; - } - - public bool Any(Expression> expression) - { - _Where(expression); - var result = Any(); - this.QueryBuilder.WhereInfos.Remove(this.QueryBuilder.WhereInfos.Last()); - return result; - } - public new ISugarQueryable Distinct() - { - QueryBuilder.IsDistinct = true; - return this; - } - #endregion - } - #endregion - #region T9 - public partial class QueryableProvider : QueryableProvider, ISugarQueryable - { - 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; - } - #region Where - 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 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 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) - { - 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(string orderFileds) - { - base.OrderBy(orderFileds); - 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 new ISugarQueryable OrderByIF(bool isOrderBy, string orderFileds) - { - if (isOrderBy) - base.OrderBy(orderFileds); - 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; - } - #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; - } - #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 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) => 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 Filter(string FilterName, bool isDisabledGobalFilter = false) - { - _Filter(FilterName, isDisabledGobalFilter); - 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 T10 - public partial class QueryableProvider : QueryableProvider, ISugarQueryable - { - 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; - } - #region Where - 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 new ISugarQueryable Where(List conditionalModels) - { - base.Where(conditionalModels); - 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 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) - { - 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(string orderFileds) - { - base.OrderBy(orderFileds); - 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 new ISugarQueryable OrderByIF(bool isOrderBy, string orderFileds) - { - if (isOrderBy) - base.OrderBy(orderFileds); - 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; - } - #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; - } - #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 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) => 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 Filter(string FilterName, bool isDisabledGobalFilter = false) - { - _Filter(FilterName, isDisabledGobalFilter); - 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 T11 - public partial class QueryableProvider : QueryableProvider, ISugarQueryable - { - 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; - } - #region Where - 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 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) - { - 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(string orderFileds) - { - base.OrderBy(orderFileds); - 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 orderFileds) - { - if (isOrderBy) - base.OrderBy(orderFileds); - 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 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 Filter(string FilterName, bool isDisabledGobalFilter = false) - { - _Filter(FilterName, isDisabledGobalFilter); - 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 - { - #region Where - 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 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) - { - 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(string orderFileds) - { - base.OrderBy(orderFileds); - 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 orderFileds) - { - if (isOrderBy) - base.OrderBy(orderFileds); - 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 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 Filter(string FilterName, bool isDisabledGobalFilter = false) - { - _Filter(FilterName, isDisabledGobalFilter); - 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 } diff --git a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider2-9.cs b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider2-9.cs new file mode 100644 index 000000000..4b5b25c38 --- /dev/null +++ b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider2-9.cs @@ -0,0 +1,6181 @@ +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 T2 + public partial class QueryableProvider : QueryableProvider, ISugarQueryable + { + 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; + } + #region Where + public new 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 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 Where(List conditionalModels) + { + base.Where(conditionalModels); + return this; + } + public new ISugarQueryable Where(IFuncModel funcModel) + { + var obj = this.SqlBuilder.FuncModelToSql(funcModel); + return this.Where(obj.Key, obj.Value); + } + public new ISugarQueryable WhereIF(bool isWhere, string whereString, object whereObj) + { + if (!isWhere) return this; + this.Where(whereString, whereObj); + return this; + } + /// + /// if a property that is not empty is a condition + /// + /// + /// + public new ISugarQueryable WhereClass(ClassType whereClass, bool ignoreDefaultValue = false) where ClassType : class, new() + { + base.WhereClass(whereClass, ignoreDefaultValue); + return this; + } + /// + /// if a property that is not empty is a condition + /// + /// + /// + public new ISugarQueryable WhereClass(List whereClassTypes, bool ignoreDefaultValue = false) where ClassType : class, new() + { + + base.WhereClass(whereClassTypes, ignoreDefaultValue); + return this; + } + #endregion + + #region Select + public ISugarQueryable Select(Expression> expression) + { + return _Select(expression); + } + + #endregion + + #region Order + public new ISugarQueryable OrderBy(string orderFileds) + { + base.OrderBy(orderFileds); + return this; + } + public ISugarQueryable OrderBy(Expression> expression, OrderByType type = OrderByType.Asc) + { + _OrderBy(expression, type); + return this; + } + public new virtual ISugarQueryable OrderByDescending(Expression> expression) + { + this._OrderBy(expression, OrderByType.Desc); + return this; + } + public virtual ISugarQueryable OrderByDescending(Expression> expression) + { + this._OrderBy(expression, OrderByType.Desc); + return this; + } + public new ISugarQueryable OrderBy(Expression> expression, OrderByType type) + { + _OrderBy(expression, type); + return this; + } + public new ISugarQueryable OrderByIF(bool isOrderBy, string orderFileds) + { + if (isOrderBy) + base.OrderBy(orderFileds); + 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; + } + #endregion + + #region GroupBy + public new virtual ISugarQueryable GroupByIF(bool isGroupBy, Expression> expression) + { + if (isGroupBy) + { + GroupBy(expression); + } + return this; + } + public virtual ISugarQueryable GroupByIF(bool isGroupBy, Expression> expression) + { + if (isGroupBy) + { + GroupBy(expression); + } + return this; + } + public new virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) + { + if (isHaving) + this._Having(expression); + return this; + } + public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) + { + if (isHaving) + this._Having(expression); + return this; + } + public new ISugarQueryable GroupBy(Expression> expression) + { + _GroupBy(expression); + return this; + } + + public ISugarQueryable GroupBy(Expression> expression) + { + _GroupBy(expression); + return this; + } + + public new ISugarQueryable Having(Expression> expression) + { + this._Having(expression); + return this; + } + + public ISugarQueryable Having(Expression> expression) + { + this._Having(expression); + return this; + } + + public new ISugarQueryable Having(string whereString, object whereObj) + { + base.Having(whereString, whereObj); + 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); + } + public Task MaxAsync(Expression> expression) + { + return _MaxAsync(expression); + } + public Task MinAsync(Expression> expression) + { + return _MinAsync(expression); + } + public Task SumAsync(Expression> expression) + { + return _SumAsync(expression); + } + public Task AvgAsync(Expression> expression) + { + return _AvgAsync(expression); + } + #endregion + + #region In + public new ISugarQueryable InIF(bool isIn, params TParamter[] pkValues) + { + if (isIn) + { + In(pkValues); + } + return this; + } + public new ISugarQueryable In(Expression> expression, params FieldType[] inValues) + { + QueryBuilder.CheckExpression(expression, "In"); + 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) + { + QueryBuilder.CheckExpression(expression, "In"); + 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; + } + + public ISugarQueryable In(Expression> expression, params FieldType[] inValues) + { + QueryBuilder.CheckExpression(expression, "In"); + var isSingle = QueryBuilder.IsSingle(); + var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); + var fieldName = lamResult.GetResultString(); + In(fieldName, inValues); + return this; + } + public ISugarQueryable In(Expression> expression, List inValues) + { + QueryBuilder.CheckExpression(expression, "In"); + var isSingle = QueryBuilder.IsSingle(); + var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); + var fieldName = lamResult.GetResultString(); + In(fieldName, inValues); + return this; + } + public ISugarQueryable In(Expression> expression, ISugarQueryable childQueryExpression) + { + var sqlObj = childQueryExpression.ToSql(); + _InQueryable(expression, sqlObj); + return this; + } + #endregion + + #region Other + public new ISugarQueryable Clone() + { + var queryable = this.Context.Queryable((t, t2) => 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 Filter(string FilterName, bool isDisabledGobalFilter = false) + { + _Filter(FilterName, isDisabledGobalFilter); + 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; + } + + public bool Any(Expression> expression) + { + _Where(expression); + var result = Any(); + this.QueryBuilder.WhereInfos.Remove(this.QueryBuilder.WhereInfos.Last()); + return result; + } + public new ISugarQueryable Distinct() + { + QueryBuilder.IsDistinct = true; + return this; + } + + public new ISugarQueryable Take(int num) + { + QueryBuilder.Take = num; + return this; + } + #endregion + } + #endregion + #region T3 + public partial class QueryableProvider : QueryableProvider, ISugarQueryable + { + 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; + } + + #region Group + public new virtual ISugarQueryable GroupByIF(bool isGroupBy, Expression> expression) + { + if (isGroupBy) + { + GroupBy(expression); + } + return this; + } + public virtual ISugarQueryable GroupByIF(bool isGroupBy, Expression> expression) + { + if (isGroupBy) + { + GroupBy(expression); + } + return this; + } + public virtual ISugarQueryable GroupByIF(bool isGroupBy, Expression> expression) + { + if (isGroupBy) + { + GroupBy(expression); + } + return this; + } + public ISugarQueryable GroupBy(Expression> expression) + { + _GroupBy(expression); + return this; + } + + public ISugarQueryable GroupBy(Expression> expression) + { + _GroupBy(expression); + return this; + } + public new ISugarQueryable GroupBy(Expression> expression) + { + _GroupBy(expression); + return this; + } + + public new ISugarQueryable Having(Expression> expression) + { + this._Having(expression); + return this; + } + + public ISugarQueryable Having(Expression> expression) + { + this._Having(expression); + return this; + } + + public ISugarQueryable Having(Expression> expression) + { + this._Having(expression); + return this; + } + + public new ISugarQueryable Having(string whereString, object whereObj) + { + base.Having(whereString, whereObj); + return this; + } + public new virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) + { + if (isHaving) + this._Having(expression); + return this; + } + public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) + { + if (isHaving) + this._Having(expression); + return this; + } + public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) + { + if (isHaving) + this._Having(expression); + return this; + } + #endregion + + #region Order + public new virtual ISugarQueryable OrderByDescending(Expression> expression) + { + this._OrderBy(expression, OrderByType.Desc); + return this; + } + public virtual ISugarQueryable OrderByDescending(Expression> expression) + { + this._OrderBy(expression, OrderByType.Desc); + return this; + } + public virtual ISugarQueryable OrderByDescending(Expression> expression) + { + this._OrderBy(expression, OrderByType.Desc); + return this; + } + public new ISugarQueryable OrderBy(string orderFileds) + { + base.OrderBy(orderFileds); + 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 OrderBy(Expression> expression, OrderByType type) + { + _OrderBy(expression, type); + return this; + } + public new ISugarQueryable OrderByIF(bool isOrderBy, string orderFileds) + { + if (isOrderBy) + base.OrderBy(orderFileds); + 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; + } + #endregion + + #region Select + public ISugarQueryable Select(Expression> expression) + { + return _Select(expression); + } + + public ISugarQueryable Select(Expression> expression) + { + return _Select(expression); + } + + public ISugarQueryable Where(Expression> expression) + { + _Where(expression); + return this; + } + #endregion + + #region Where + public ISugarQueryable Where(Expression> expression) + { + _Where(expression); + return this; + } + + public new ISugarQueryable Where(Expression> expression) + { + _Where(expression); + return this; + } + public new ISugarQueryable Where(List conditionalModels) + { + base.Where(conditionalModels); + return this; + } + public new ISugarQueryable Where(IFuncModel funcModel) + { + var obj = this.SqlBuilder.FuncModelToSql(funcModel); + return this.Where(obj.Key, obj.Value); + } + 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 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; + } + /// + /// if a property that is not empty is a condition + /// + /// + /// + public new ISugarQueryable WhereClass(ClassType whereClass, bool ignoreDefaultValue = false) where ClassType : class, new() + { + base.WhereClass(whereClass, ignoreDefaultValue); + return this; + } + /// + /// if a property that is not empty is a condition + /// + /// + /// + public new ISugarQueryable WhereClass(List whereClassTypes, bool ignoreDefaultValue = false) where ClassType : class, new() + { + + base.WhereClass(whereClassTypes, ignoreDefaultValue); + 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); + } + public Task MaxAsync(Expression> expression) + { + return _MaxAsync(expression); + } + public Task MinAsync(Expression> expression) + { + return _MinAsync(expression); + } + public Task SumAsync(Expression> expression) + { + return _SumAsync(expression); + } + public Task AvgAsync(Expression> expression) + { + return _AvgAsync(expression); + } + #endregion + + #region In + public new ISugarQueryable InIF(bool isIn, params TParamter[] pkValues) + { + if (isIn) + { + In(pkValues); + } + return this; + } + public new ISugarQueryable In(Expression> expression, params FieldType[] inValues) + { + QueryBuilder.CheckExpression(expression, "In"); + 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) + { + QueryBuilder.CheckExpression(expression, "In"); + 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; + } + + public ISugarQueryable In(Expression> expression, params FieldType[] inValues) + { + QueryBuilder.CheckExpression(expression, "In"); + var isSingle = QueryBuilder.IsSingle(); + var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); + var fieldName = lamResult.GetResultString(); + In(fieldName, inValues); + return this; + } + public ISugarQueryable In(Expression> expression, List inValues) + { + QueryBuilder.CheckExpression(expression, "In"); + var isSingle = QueryBuilder.IsSingle(); + var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); + var fieldName = lamResult.GetResultString(); + In(fieldName, inValues); + return this; + } + public ISugarQueryable In(Expression> expression, ISugarQueryable childQueryExpression) + { + var sqlObj = childQueryExpression.ToSql(); + _InQueryable(expression, sqlObj); + return this; + } + + public ISugarQueryable In(Expression> expression, params FieldType[] inValues) + { + QueryBuilder.CheckExpression(expression, "In"); + var isSingle = QueryBuilder.IsSingle(); + var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); + var fieldName = lamResult.GetResultString(); + In(fieldName, inValues); + return this; + } + public ISugarQueryable In(Expression> expression, List inValues) + { + QueryBuilder.CheckExpression(expression, "In"); + var isSingle = QueryBuilder.IsSingle(); + var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); + var fieldName = lamResult.GetResultString(); + In(fieldName, inValues); + return this; + } + public ISugarQueryable In(Expression> expression, ISugarQueryable childQueryExpression) + { + var sqlObj = childQueryExpression.ToSql(); + _InQueryable(expression, sqlObj); + return this; + } + #endregion + + #region Other + public new ISugarQueryable Take(int num) + { + QueryBuilder.Take = num; + return this; + } + public new ISugarQueryable Clone() + { + var queryable = this.Context.Queryable((t, t2, t3) => 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 Filter(string FilterName, bool isDisabledGobalFilter = false) + { + _Filter(FilterName, isDisabledGobalFilter); + 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; + } + + public bool Any(Expression> expression) + { + _Where(expression); + var result = Any(); + this.QueryBuilder.WhereInfos.Remove(this.QueryBuilder.WhereInfos.Last()); + return result; + } + public new ISugarQueryable Distinct() + { + QueryBuilder.IsDistinct = true; + return this; + } + #endregion + } + #endregion + #region T4 + public partial class QueryableProvider : QueryableProvider, ISugarQueryable + { + 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; + } + + #region Where + 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 new ISugarQueryable Where(List conditionalModels) + { + base.Where(conditionalModels); + return this; + } + public new ISugarQueryable Where(IFuncModel funcModel) + { + var obj = this.SqlBuilder.FuncModelToSql(funcModel); + return this.Where(obj.Key, obj.Value); + } + 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 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; + } + /// + /// if a property that is not empty is a condition + /// + /// + /// + public new ISugarQueryable WhereClass(ClassType whereClass, bool ignoreDefaultValue = false) where ClassType : class, new() + { + base.WhereClass(whereClass, ignoreDefaultValue); + return this; + } + /// + /// if a property that is not empty is a condition + /// + /// + /// + public new ISugarQueryable WhereClass(List whereClassTypes, bool ignoreDefaultValue = false) where ClassType : class, new() + { + + base.WhereClass(whereClassTypes, ignoreDefaultValue); + return this; + } + #endregion + + #region Select + 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 virtual ISugarQueryable OrderByDescending(Expression> expression) + { + this._OrderBy(expression, OrderByType.Desc); + return this; + } + public virtual ISugarQueryable OrderByDescending(Expression> expression) + { + this._OrderBy(expression, OrderByType.Desc); + return this; + } + public virtual ISugarQueryable OrderByDescending(Expression> expression) + { + this._OrderBy(expression, OrderByType.Desc); + return this; + } + public virtual ISugarQueryable OrderByDescending(Expression> expression) + { + this._OrderBy(expression, OrderByType.Desc); + return this; + } + public new ISugarQueryable OrderBy(string orderFileds) + { + base.OrderBy(orderFileds); + 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 new ISugarQueryable OrderByIF(bool isOrderBy, string orderFileds) + { + if (isOrderBy) + base.OrderBy(orderFileds); + 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; + } + #endregion + + #region GroupBy + public new virtual ISugarQueryable GroupByIF(bool isGroupBy, Expression> expression) + { + if (isGroupBy) + { + GroupBy(expression); + } + return this; + } + public virtual ISugarQueryable GroupByIF(bool isGroupBy, Expression> expression) + { + if (isGroupBy) + { + GroupBy(expression); + } + return this; + } + public virtual ISugarQueryable GroupByIF(bool isGroupBy, Expression> expression) + { + if (isGroupBy) + { + GroupBy(expression); + } + return this; + } + public virtual ISugarQueryable GroupByIF(bool isGroupBy, Expression> expression) + { + if (isGroupBy) + { + GroupBy(expression); + } + return this; + } + 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 new ISugarQueryable Having(Expression> expression) + { + this._Having(expression); + return this; + } + + public ISugarQueryable Having(Expression> expression) + { + this._Having(expression); + return this; + } + + public ISugarQueryable Having(Expression> expression) + { + this._Having(expression); + return this; + } + + public ISugarQueryable Having(Expression> expression) + { + this._Having(expression); + return this; + } + + public new ISugarQueryable Having(string whereString, object whereObj) + { + base.Having(whereString, whereObj); + return this; + } + + public new virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) + { + if (isHaving) + this._Having(expression); + return this; + } + public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) + { + if (isHaving) + this._Having(expression); + return this; + } + public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) + { + if (isHaving) + this._Having(expression); + return this; + } + public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) + { + if (isHaving) + this._Having(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 InIF(bool isIn, params TParamter[] pkValues) + { + if (isIn) + { + In(pkValues); + } + return this; + } + public new ISugarQueryable In(Expression> expression, params FieldType[] inValues) + { + QueryBuilder.CheckExpression(expression, "In"); + 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) + { + QueryBuilder.CheckExpression(expression, "In"); + 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; + } + + public ISugarQueryable In(Expression> expression, params FieldType[] inValues) + { + QueryBuilder.CheckExpression(expression, "In"); + var isSingle = QueryBuilder.IsSingle(); + var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); + var fieldName = lamResult.GetResultString(); + In(fieldName, inValues); + return this; + } + public ISugarQueryable In(Expression> expression, List inValues) + { + QueryBuilder.CheckExpression(expression, "In"); + var isSingle = QueryBuilder.IsSingle(); + var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); + var fieldName = lamResult.GetResultString(); + In(fieldName, inValues); + return this; + } + public ISugarQueryable In(Expression> expression, ISugarQueryable childQueryExpression) + { + var sqlObj = childQueryExpression.ToSql(); + _InQueryable(expression, sqlObj); + return this; + } + + public ISugarQueryable In(Expression> expression, params FieldType[] inValues) + { + QueryBuilder.CheckExpression(expression, "In"); + var isSingle = QueryBuilder.IsSingle(); + var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); + var fieldName = lamResult.GetResultString(); + In(fieldName, inValues); + return this; + } + public ISugarQueryable In(Expression> expression, List inValues) + { + QueryBuilder.CheckExpression(expression, "In"); + var isSingle = QueryBuilder.IsSingle(); + var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); + var fieldName = lamResult.GetResultString(); + In(fieldName, inValues); + return this; + } + public ISugarQueryable In(Expression> expression, ISugarQueryable childQueryExpression) + { + var sqlObj = childQueryExpression.ToSql(); + _InQueryable(expression, sqlObj); + return this; + } + + public ISugarQueryable In(Expression> expression, params FieldType[] inValues) + { + QueryBuilder.CheckExpression(expression, "In"); + var isSingle = QueryBuilder.IsSingle(); + var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); + var fieldName = lamResult.GetResultString(); + In(fieldName, inValues); + return this; + } + public ISugarQueryable In(Expression> expression, List inValues) + { + QueryBuilder.CheckExpression(expression, "In"); + var isSingle = QueryBuilder.IsSingle(); + var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple); + var fieldName = lamResult.GetResultString(); + In(fieldName, inValues); + return this; + } + public ISugarQueryable In(Expression> expression, ISugarQueryable childQueryExpression) + { + var sqlObj = childQueryExpression.ToSql(); + _InQueryable(expression, sqlObj); + return this; + } + #endregion + + + #region Other + public new ISugarQueryable Take(int num) + { + QueryBuilder.Take = num; + return this; + } + public new ISugarQueryable Clone() + { + var queryable = this.Context.Queryable((t, t2, t3, t4) => 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 Filter(string FilterName, bool isDisabledGobalFilter = false) + { + _Filter(FilterName, isDisabledGobalFilter); + 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; + } + + public bool Any(Expression> expression) + { + _Where(expression); + var result = Any(); + this.QueryBuilder.WhereInfos.Remove(this.QueryBuilder.WhereInfos.Last()); + return result; + } + public new ISugarQueryable Distinct() + { + QueryBuilder.IsDistinct = true; + return this; + } + #endregion + } + #endregion + #region T5 + public partial class QueryableProvider : QueryableProvider, ISugarQueryable + { + 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; + } + + #region Where + 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 new ISugarQueryable Where(List conditionalModels) + { + base.Where(conditionalModels); + return this; + } + public new ISugarQueryable Where(IFuncModel funcModel) + { + var obj = this.SqlBuilder.FuncModelToSql(funcModel); + return this.Where(obj.Key, obj.Value); + } + 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 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; + } + + /// + /// if a property that is not empty is a condition + /// + /// + /// + public new ISugarQueryable WhereClass(ClassType whereClass, bool ignoreDefaultValue = false) where ClassType : class, new() + { + base.WhereClass(whereClass, ignoreDefaultValue); + return this; + } + /// + /// if a property that is not empty is a condition + /// + /// + /// + public new ISugarQueryable WhereClass(List whereClassTypes, bool ignoreDefaultValue = false) where ClassType : class, new() + { + + base.WhereClass(whereClassTypes, ignoreDefaultValue); + return this; + } + + #endregion + + #region Select + 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 virtual ISugarQueryable OrderByDescending(Expression> expression) + { + this._OrderBy(expression, OrderByType.Desc); + return this; + } + public virtual ISugarQueryable OrderByDescending(Expression> expression) + { + this._OrderBy(expression, OrderByType.Desc); + return this; + } + public virtual ISugarQueryable OrderByDescending(Expression> expression) + { + this._OrderBy(expression, OrderByType.Desc); + return this; + } + public virtual ISugarQueryable OrderByDescending(Expression> expression) + { + this._OrderBy(expression, OrderByType.Desc); + return this; + } + public virtual ISugarQueryable OrderByDescending(Expression> expression) + { + this._OrderBy(expression, OrderByType.Desc); + return this; + } + public new ISugarQueryable OrderBy(string orderFileds) + { + base.OrderBy(orderFileds); + 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 new ISugarQueryable OrderByIF(bool isOrderBy, string orderFileds) + { + if (isOrderBy) + base.OrderBy(orderFileds); + 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; + } + #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 new ISugarQueryable Having(Expression> expression) + { + this._Having(expression); + return this; + } + + public ISugarQueryable Having(Expression> expression) + { + this._Having(expression); + return this; + } + + public ISugarQueryable Having(Expression> expression) + { + this._Having(expression); + return this; + } + + public ISugarQueryable Having(Expression> expression) + { + this._Having(expression); + return this; + } + + public ISugarQueryable Having(Expression> expression) + { + this._Having(expression); + return this; + } + + public new ISugarQueryable Having(string whereString, object whereObj) + { + base.Having(whereString, whereObj); + return this; + } + + public new virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) + { + if (isHaving) + this._Having(expression); + return this; + } + public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) + { + if (isHaving) + this._Having(expression); + return this; + } + public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) + { + if (isHaving) + this._Having(expression); + return this; + } + public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) + { + if (isHaving) + this._Having(expression); + return this; + } + public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) + { + if (isHaving) + this._Having(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 Take(int num) + { + QueryBuilder.Take = num; + return this; + } + public new ISugarQueryable Clone() + { + var queryable = this.Context.Queryable((t, t2, t3, t4, t5) => 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 Filter(string FilterName, bool isDisabledGobalFilter = false) + { + _Filter(FilterName, isDisabledGobalFilter); + 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; + } + + public bool Any(Expression> expression) + { + _Where(expression); + var result = Any(); + this.QueryBuilder.WhereInfos.Remove(this.QueryBuilder.WhereInfos.Last()); + return result; + } + public new ISugarQueryable Distinct() + { + QueryBuilder.IsDistinct = true; + return this; + } + #endregion + } + #endregion + #region T6 + public partial class QueryableProvider : QueryableProvider, ISugarQueryable + { + 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; + } + #region Where + 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 new ISugarQueryable Where(List conditionalModels) + { + base.Where(conditionalModels); + return this; + } + public new ISugarQueryable Where(IFuncModel funcModel) + { + var obj = this.SqlBuilder.FuncModelToSql(funcModel); + return this.Where(obj.Key, obj.Value); + } + 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 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; + } + + /// + /// if a property that is not empty is a condition + /// + /// + /// + public new ISugarQueryable WhereClass(ClassType whereClass, bool ignoreDefaultValue = false) where ClassType : class, new() + { + base.WhereClass(whereClass, ignoreDefaultValue); + return this; + } + /// + /// if a property that is not empty is a condition + /// + /// + /// + public new ISugarQueryable WhereClass(List whereClassTypes, bool ignoreDefaultValue = false) where ClassType : class, new() + { + + base.WhereClass(whereClassTypes, ignoreDefaultValue); + return this; + } + #endregion + + #region Select + 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 virtual ISugarQueryable OrderByDescending(Expression> expression) + { + this._OrderBy(expression, OrderByType.Desc); + return this; + } + public virtual ISugarQueryable OrderByDescending(Expression> expression) + { + this._OrderBy(expression, OrderByType.Desc); + return this; + } + public virtual ISugarQueryable OrderByDescending(Expression> expression) + { + this._OrderBy(expression, OrderByType.Desc); + return this; + } + public virtual ISugarQueryable OrderByDescending(Expression> expression) + { + this._OrderBy(expression, OrderByType.Desc); + return this; + } + public virtual ISugarQueryable OrderByDescending(Expression> expression) + { + this._OrderBy(expression, OrderByType.Desc); + return this; + } + public virtual ISugarQueryable OrderByDescending(Expression> expression) + { + this._OrderBy(expression, OrderByType.Desc); + return this; + } + + public new ISugarQueryable OrderBy(string orderFileds) + { + base.OrderBy(orderFileds); + 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 new ISugarQueryable OrderByIF(bool isOrderBy, string orderFileds) + { + if (isOrderBy) + base.OrderBy(orderFileds); + 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; + } + #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 new ISugarQueryable Having(Expression> expression) + { + this._Having(expression); + return this; + } + + public ISugarQueryable Having(Expression> expression) + { + this._Having(expression); + return this; + } + + public ISugarQueryable Having(Expression> expression) + { + this._Having(expression); + return this; + } + + public ISugarQueryable Having(Expression> expression) + { + this._Having(expression); + return this; + } + + public ISugarQueryable Having(Expression> expression) + { + this._Having(expression); + return this; + } + public ISugarQueryable Having(Expression> expression) + { + this._Having(expression); + return this; + } + + public new ISugarQueryable Having(string whereString, object whereObj) + { + base.Having(whereString, whereObj); + return this; + } + + public new virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) + { + if (isHaving) + this._Having(expression); + return this; + } + public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) + { + if (isHaving) + this._Having(expression); + return this; + } + public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) + { + if (isHaving) + this._Having(expression); + return this; + } + public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) + { + if (isHaving) + this._Having(expression); + return this; + } + public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) + { + if (isHaving) + this._Having(expression); + return this; + } + public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) + { + if (isHaving) + this._Having(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 Take(int num) + { + QueryBuilder.Take = num; + return this; + } + public new ISugarQueryable Clone() + { + var queryable = this.Context.Queryable((t, t2, t3, t4, t5, T6) => 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 Filter(string FilterName, bool isDisabledGobalFilter = false) + { + _Filter(FilterName, isDisabledGobalFilter); + 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; + } + + public bool Any(Expression> expression) + { + _Where(expression); + var result = Any(); + this.QueryBuilder.WhereInfos.Remove(this.QueryBuilder.WhereInfos.Last()); + return result; + } + public new ISugarQueryable Distinct() + { + QueryBuilder.IsDistinct = true; + return this; + } + #endregion + } + #endregion + #region T7 + public partial class QueryableProvider : QueryableProvider, ISugarQueryable + { + 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; + } + #region Where + 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 new ISugarQueryable Where(List conditionalModels) + { + base.Where(conditionalModels); + 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 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; + } + /// + /// if a property that is not empty is a condition + /// + /// + /// + public new ISugarQueryable WhereClass(ClassType whereClass, bool ignoreDefaultValue = false) where ClassType : class, new() + { + base.WhereClass(whereClass, ignoreDefaultValue); + return this; + } + /// + /// if a property that is not empty is a condition + /// + /// + /// + public new ISugarQueryable WhereClass(List whereClassTypes, bool ignoreDefaultValue = false) where ClassType : class, new() + { + + base.WhereClass(whereClassTypes, ignoreDefaultValue); + return this; + } + #endregion + + #region Select + 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(string orderFileds) + { + base.OrderBy(orderFileds); + 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; + } + #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 new ISugarQueryable OrderByIF(bool isOrderBy, string orderFileds) + { + if (isOrderBy) + base.OrderBy(orderFileds); + 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 new virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) + { + if (isHaving) + this._Having(expression); + return this; + } + public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) + { + if (isHaving) + this._Having(expression); + return this; + } + public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) + { + if (isHaving) + this._Having(expression); + return this; + } + public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) + { + if (isHaving) + this._Having(expression); + return this; + } + public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) + { + if (isHaving) + this._Having(expression); + return this; + } + public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) + { + if (isHaving) + this._Having(expression); + return this; + } + public virtual ISugarQueryable HavingIF(bool isHaving, Expression> expression) + { + if (isHaving) + this._Having(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 Take(int num) + { + QueryBuilder.Take = num; + return this; + } + public new ISugarQueryable Clone() + { + var queryable = this.Context.Queryable((t, t2, t3, t4, t5, T6, t7) => 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 Filter(string FilterName, bool isDisabledGobalFilter = false) + { + _Filter(FilterName, isDisabledGobalFilter); + 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; + } + + public bool Any(Expression> expression) + { + _Where(expression); + var result = Any(); + this.QueryBuilder.WhereInfos.Remove(this.QueryBuilder.WhereInfos.Last()); + return result; + } + public new ISugarQueryable Distinct() + { + QueryBuilder.IsDistinct = true; + return this; + } + #endregion + } + #endregion + #region T8 + public partial class QueryableProvider : QueryableProvider, ISugarQueryable + { + 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; + } + #region Where + 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 new ISugarQueryable Where(List conditionalModels) + { + base.Where(conditionalModels); + 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 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; + } + /// + /// if a property that is not empty is a condition + /// + /// + /// + public new ISugarQueryable WhereClass(ClassType whereClass, bool ignoreDefaultValue = false) where ClassType : class, new() + { + base.WhereClass(whereClass, ignoreDefaultValue); + return this; + } + /// + /// if a property that is not empty is a condition + /// + /// + /// + public new ISugarQueryable WhereClass(List whereClassTypes, bool ignoreDefaultValue = false) where ClassType : class, new() + { + + base.WhereClass(whereClassTypes, ignoreDefaultValue); + return this; + } + #endregion + + #region Select + 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(string orderFileds) + { + base.OrderBy(orderFileds); + 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 new ISugarQueryable OrderByIF(bool isOrderBy, string orderFileds) + { + if (isOrderBy) + base.OrderBy(orderFileds); + 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; + } + #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; + } + + #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 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) => 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 Filter(string FilterName, bool isDisabledGobalFilter = false) + { + _Filter(FilterName, isDisabledGobalFilter); + 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; + } + + public bool Any(Expression> expression) + { + _Where(expression); + var result = Any(); + this.QueryBuilder.WhereInfos.Remove(this.QueryBuilder.WhereInfos.Last()); + return result; + } + public new ISugarQueryable Distinct() + { + QueryBuilder.IsDistinct = true; + return this; + } + #endregion + } + #endregion + #region T9 + public partial class QueryableProvider : QueryableProvider, ISugarQueryable + { + 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; + } + #region Where + 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 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 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) + { + 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(string orderFileds) + { + base.OrderBy(orderFileds); + 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 new ISugarQueryable OrderByIF(bool isOrderBy, string orderFileds) + { + if (isOrderBy) + base.OrderBy(orderFileds); + 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; + } + #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; + } + #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 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) => 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 Filter(string FilterName, bool isDisabledGobalFilter = false) + { + _Filter(FilterName, isDisabledGobalFilter); + 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 T10 + public partial class QueryableProvider : QueryableProvider, ISugarQueryable + { + 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; + } + #region Where + 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 new ISugarQueryable Where(List conditionalModels) + { + base.Where(conditionalModels); + 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 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) + { + 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(string orderFileds) + { + base.OrderBy(orderFileds); + 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 new ISugarQueryable OrderByIF(bool isOrderBy, string orderFileds) + { + if (isOrderBy) + base.OrderBy(orderFileds); + 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; + } + #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; + } + #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 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) => 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 Filter(string FilterName, bool isDisabledGobalFilter = false) + { + _Filter(FilterName, isDisabledGobalFilter); + 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 T11 + public partial class QueryableProvider : QueryableProvider, ISugarQueryable + { + 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; + } + #region Where + 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 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) + { + 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(string orderFileds) + { + base.OrderBy(orderFileds); + 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 orderFileds) + { + if (isOrderBy) + base.OrderBy(orderFileds); + 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 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 Filter(string FilterName, bool isDisabledGobalFilter = false) + { + _Filter(FilterName, isDisabledGobalFilter); + 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 + { + #region Where + 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 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) + { + 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(string orderFileds) + { + base.OrderBy(orderFileds); + 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 orderFileds) + { + if (isOrderBy) + base.OrderBy(orderFileds); + 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 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 Filter(string FilterName, bool isDisabledGobalFilter = false) + { + _Filter(FilterName, isDisabledGobalFilter); + 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 +} diff --git a/Src/Asp.Net/SqlSugar/SqlSugar.csproj b/Src/Asp.Net/SqlSugar/SqlSugar.csproj index eb1717087..6b3dad439 100644 --- a/Src/Asp.Net/SqlSugar/SqlSugar.csproj +++ b/Src/Asp.Net/SqlSugar/SqlSugar.csproj @@ -114,6 +114,8 @@ + +