private static IMtQueryable <T> CriteriaToMtQuery( List <FilterConditionDTO> conditions, IMtQueryable <T> queryable) { var predicateBuilder = new FilterConditionPredicateBuilder <T>(conditions); queryable = queryable.Where(predicateBuilder.ToPredicate()); return(queryable); }
// Currently we support only string of MtWhere. All Expressions from MtWhere are combined using 'and' into one expression. private static Expression <Func <T, bool> > BuildExpression(IMtQueryable <T> queryable) { IMtQueryable <T> root = queryable; var condtions = new List <Expression <Func <T, bool> > >(); while (root.Previous != null) { if (root is MtQueryAll <T> ) { break; } if (root is MtWhere <T> ) { condtions.Add(((MtWhere <T>)root).Condition); } else { throw new NotSupportedException(string.Format("Query part {0} is not supported", root.GetType().Name)); } root = root.Previous; } Expression <Func <T, bool> > result; if (condtions.Count == 0) { result = x => true; } else if (condtions.Count == 1) { result = condtions[0]; } else { var sourceParameter = condtions[0].Parameters[0]; var temp = ReplaceParameter(condtions[condtions.Count - 1], sourceParameter); for (int i = condtions.Count - 2; i >= 0; i--) { temp = Expression.AndAlso(temp, ReplaceParameter(condtions[i], sourceParameter)); } result = Expression.Lambda <Func <T, bool> >(temp, sourceParameter); } return(result); }
protected MtQueryable(IMtQueryable <T> previous, IMtQueryExecutor <T> executor) { Previous = previous; Executor = executor; }
protected MtQueryable(IMtQueryable <T> prev) { Previous = prev; Executor = prev.Executor; }
public static IMtQueryable <T> Where <T>(this IMtQueryable <T> that, Expression <Func <T, bool> > condition) where T : Manifest { return(new MtWhere <T>(that, condition)); }
public static int MtCount <T>(this IMtQueryable <T> that, Expression <Func <T, bool> > condition) where T : Manifest { var where = new MtWhere <T>(that, condition); return(where.Executor.Count(where)); }
public static int MtCount <T>(this IMtQueryable <T> that) where T : Manifest { return(that.Executor.Count(that)); }
public MtWhere(IMtQueryable <T> prev, Expression <Func <T, bool> > condition) : base(prev) { Condition = condition; }
public int Count(IMtQueryable <T> queryable) { var result = BuildExpression(queryable); return(_mtObjectRepository.Count(_currentAccountId, result)); }
public IEnumerator <T> RunQuery(IMtQueryable <T> queryable) { var result = BuildExpression(queryable); return(_mtObjectRepository.Query(_currentAccountId, result).GetEnumerator()); }