using Ant.Core; using Ant.ORM; using Ant.Query.QueryExpressions; using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; namespace Ant.Query { class GroupingQuery : IGroupingQuery { Queryable _fromQuery; List _groupPredicates; List _havingPredicates; public GroupingQuery(Queryable fromQuery, LambdaExpression predicate) { this._fromQuery = fromQuery; this._groupPredicates = new List(1); this._havingPredicates = new List(); this._groupPredicates.Add(predicate); } public GroupingQuery(Queryable fromQuery, List groupPredicates, List havingPredicates) { this._fromQuery = fromQuery; this._groupPredicates = groupPredicates; this._havingPredicates = havingPredicates; } public IGroupingQuery ThenBy(Expression> predicate) { List groupPredicates = new List(this._groupPredicates.Count + 1); groupPredicates.AddRange(this._groupPredicates); groupPredicates.Add(predicate); List havingPredicates = new List(this._havingPredicates.Count); havingPredicates.AddRange(this._havingPredicates); return new GroupingQuery(this._fromQuery, groupPredicates, havingPredicates); } public IGroupingQuery Having(Expression> predicate) { List groupPredicates = new List(this._groupPredicates.Count); groupPredicates.AddRange(this._groupPredicates); List havingPredicates = new List(this._havingPredicates.Count + 1); havingPredicates.AddRange(this._havingPredicates); havingPredicates.Add(predicate); return new GroupingQuery(this._fromQuery, groupPredicates, havingPredicates); } public IQuery Select(Expression> selector) { var e = new GroupingQueryExpression(typeof(TResult), this._fromQuery.QueryExpression, selector); e.GroupPredicates.AddRange(this._groupPredicates); e.HavingPredicates.AddRange(this._havingPredicates); return new Queryable(this._fromQuery.DbContext, e, this._fromQuery._trackEntity); } } }