Пример #1
0
        public IQueryable Sort()
        {
            IQueryable query   = queryable;
            bool       isFirst = true;

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

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

                query = query.Provider.CreateQuery(
                    Expression.Call(
                        typeof(Queryable),
                        methodName,
                        new[] { query.ElementType, expression.Body.Type },
                        query.Expression,
                        Expression.Quote(expression)));
            }
            return(query);
        }
        public static MemberAccessExpressionBuilderBase MemberAccess(Expression expression, Type memberType, string memberName)
        {
            var builder = ExpressionBuilderFactory.MemberAccess(expression.GetUnderlyingElementType(), memberType, memberName);

            //builder.Options.LiftMemberAccessToNull = source.Provider.IsLinqToObjectsProvider();
            builder.Options.LiftMemberAccessToNull = false;

            return(builder);
        }
Пример #3
0
        private LambdaExpression CreateMemberSelectorExpression()
        {
            var memberAccessBuilder = ExpressionBuilderFactory.MemberAccess(this.ItemType, null, this.Function.SourceField);

            memberAccessBuilder.Options.CopyFrom(this.Options);

            var memberExpression = memberAccessBuilder.CreateMemberAccessExpression();

            memberExpression = ConvertMemberAccessExpression(memberExpression);

            return(Expression.Lambda(memberExpression, memberAccessBuilder.ParameterExpression));
        }
Пример #4
0
        internal static IQueryable SelectDistinct(this IQueryable source, Type propertyType, string propertyName)
        {
            var builder = ExpressionBuilderFactory.MemberAccess(source, propertyType, propertyName);

            LambdaExpression lambda = builder.CreateLambdaExpression();

            var queryable = source.Select(lambda);

            queryable = queryable.Provider.CreateQuery(
                Expression.Call(
                    typeof(Queryable),
                    "Distinct",
                    new[] { lambda.Body.Type },
                    queryable.Expression));

            return(queryable);
        }
Пример #5
0
        protected virtual Expression CreateMemberExpression()
        {
            Type memberType = FilterDescriptor.MemberType;
            MemberAccessExpressionBuilderBase expressionBuilderBase =
                ExpressionBuilderFactory.MemberAccess(ParameterExpression.Type, memberType, FilterDescriptor.Member);

            expressionBuilderBase.Options.CopyFrom(Options);
            expressionBuilderBase.ParameterExpression = ParameterExpression;
            Expression expression = expressionBuilderBase.CreateMemberAccessExpression();

            if (memberType != null &&
                TypeExtensions.GetNonNullableType(expression.Type) != TypeExtensions.GetNonNullableType(memberType))
            {
                expression = Expression.Convert(expression, memberType);
            }
            return(expression);
        }
        protected virtual Expression CreateMemberExpression()
        {
            var memberType = this.FilterDescriptor.MemberType;

            var memberAccessBuilder =
                ExpressionBuilderFactory.MemberAccess(this.ParameterExpression.Type, memberType, this.FilterDescriptor.Member);

            memberAccessBuilder.Options.CopyFrom(this.Options);

            memberAccessBuilder.ParameterExpression = this.ParameterExpression;

            Expression memberAccessExpression = memberAccessBuilder.CreateMemberAccessExpression();

            if (memberType != null && memberAccessExpression.Type.GetNonNullableType() != memberType.GetNonNullableType())
            {
                memberAccessExpression = Expression.Convert(memberAccessExpression, memberType);
            }

            return(memberAccessExpression);
        }
Пример #7
0
        public static LambdaExpression Lambda <T>(string memberName, bool checkForNull)
        {
            MemberAccessExpressionBuilderBase expressionBuilder = ExpressionBuilderFactory.MemberAccess(typeof(T), memberName, checkForNull);

            return(expressionBuilder.CreateLambdaExpression());
        }