Example #1
0
        public override IQueryable GetQueryable(IQueryable source)
        {
            if (source == null)
            {
                return(null);
            }

            if ((DataFields == null) || String.IsNullOrEmpty(DataFields.Trim()))
            {
                throw new InvalidOperationException(AtlasWeb.Expressions_DataFieldRequired);
            }

            IDictionary <string, object> values = GetValues();

            if (values.Count == 0)
            {
                throw new InvalidOperationException(AtlasWeb.SearchExpression_ParameterRequired);
            }

            string query = Convert.ToString(values.First().Value, CultureInfo.CurrentCulture);

            if (String.IsNullOrEmpty(query))
            {
                return(null);
            }

            string[] properties = DataFields.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            // Use the or expression to or the fields together
            List <Expression> searchExpressions = new List <Expression>();

            ParameterExpression parameterExpression = Expression.Parameter(source.ElementType, String.Empty);

            foreach (string p in properties)
            {
                Expression property = ExpressionHelper.CreatePropertyExpression(parameterExpression, p.Trim());
                searchExpressions.Add(CreateCallExpression(property, query));
            }

            return(ExpressionHelper.Where(source,
                                          Expression.Lambda(ExpressionHelper.Or(searchExpressions),
                                                            parameterExpression)));
        }