private IQueryable BindGroupBy(IQueryable query) { LambdaExpression groupLambda = null; if (_groupingProperties != null && _groupingProperties.Any()) { // Generates expression // .GroupBy($it => new DynamicType1() // { // Prop1 = $it.Prop1, // Prop2 = $it.Prop2, // Prop3 = $it.NavProp.Prop3 // ... // }) List <MemberAssignment> wrapperTypeMemberAssignments = CreateGroupByMemberAssignments(_groupByClrType, _groupingProperties); groupLambda = Expression.Lambda(Expression.MemberInit(Expression.New(this._groupByClrType), wrapperTypeMemberAssignments), this._lambdaParameter); } else { // We do not have properties to aggregate // .GroupBy($it => new GroupByWrapper()) groupLambda = Expression.Lambda(Expression.New(this._groupByClrType), this._lambdaParameter); } return(ExpressionHelpers.GroupBy(query, groupLambda, this._elementType, this._groupByClrType)); }
private IQueryable BindGroupBy(IQueryable query) { LambdaExpression groupLambda = null; Type elementType = query.ElementType; if (_groupingProperties != null && _groupingProperties.Any()) { // Generates expression // .GroupBy($it => new DynamicTypeWrapper() // { // GroupByContainer => new AggregationPropertyContainer() { // Name = "Prop1", // Value = $it.Prop1, // Next = new AggregationPropertyContainer() { // Name = "Prop2", // Value = $it.Prop2, // int // Next = new LastInChain() { // Name = "Prop3", // Value = $it.Prop3 // } // } // } // }) List <NamedPropertyExpression> properties = CreateGroupByMemberAssignments(_groupingProperties); var wrapperProperty = typeof(GroupByWrapper).GetProperty(GroupByContainerProperty); List <MemberAssignment> wta = new List <MemberAssignment>(); wta.Add(Expression.Bind(wrapperProperty, AggregationPropertyContainer.CreateNextNamedPropertyContainer(properties))); groupLambda = Expression.Lambda(Expression.MemberInit(Expression.New(typeof(GroupByWrapper)), wta), LambdaParameter); } else { // We do not have properties to aggregate // .GroupBy($it => new NoGroupByWrapper()) groupLambda = Expression.Lambda(Expression.New(this._groupByClrType), this.LambdaParameter); } return(ExpressionHelpers.GroupBy(query, groupLambda, elementType, this._groupByClrType)); }