protected override LambdaExpression CreateGroupByExpression()
        {
            var memberAccessBuilder = ExpressionBuilderFactoryEx.MemberAccess(this.Queryable, this.groupDescriptor.MemberType, this.groupDescriptor.Member);

            memberAccessBuilder.ParameterExpression = this.ParameterExpression;
            return(memberAccessBuilder.CreateLambdaExpression());
        }
Esempio n. 2
0
        public MethodCallExpression GetSortExpression()
        {
            MethodCallExpression mce = null;
            bool isFirst             = true;

            foreach (var descriptor in this.sortDescriptors)
            {
                Type memberType        = typeof(object);
                var  descriptorBuilder = ExpressionBuilderFactoryEx.MemberAccess(this.parentExpression, memberType, descriptor.Member);
                var  expression        = descriptorBuilder.CreateLambdaExpression();

                string methodName = "";
                if (isFirst)
                {
                    methodName = descriptor.SortDirection == ListSortDirection.Ascending ?
                                 "OrderBy" : "OrderByDescending";
                }
                else
                {
                    methodName = descriptor.SortDirection == ListSortDirection.Ascending ?
                                 "ThenBy" : "ThenByDescending";
                }

                mce = Expression.Call(
                    typeof(Queryable),
                    methodName,
                    new[] { parentExpression.GetUnderlyingElementType(), expression.Body.Type },
                    isFirst ? parentExpression : mce,
                    Expression.Quote(expression));

                isFirst = false;
            }

            return(mce);
        }