Пример #1
0
        /** QueryField **/

        /// <summary>
        /// Creates a new instance of <see cref="QueryGroup"/> object.
        /// </summary>
        /// <param name="queryField">The field to be grouped for the query expression.</param>
        public QueryGroup(QueryField queryField) :
            this(queryField?.AsEnumerable(),
                 (IEnumerable <QueryGroup>)null,
                 Conjunction.And,
                 false)
        {
        }
Пример #2
0
 /// <summary>
 /// Creates a new instance of <see cref="QueryGroup"/> object.
 /// </summary>
 /// <param name="queryField">The field to be grouped for the query expression.</param>
 /// <param name="isNot">The prefix to be added whether the field value is in opposite state.</param>
 public QueryGroup(QueryField queryField,
                   bool isNot) :
     this(queryField?.AsEnumerable(),
          (IEnumerable <QueryGroup>)null,
          Conjunction.And,
          isNot)
 {
 }
Пример #3
0
 /// <summary>
 /// Creates a new instance of <see cref="QueryGroup"/> object.
 /// </summary>
 /// <param name="queryField">The field to be grouped for the query expression.</param>
 /// <param name="queryGroup">The child query group to be grouped for the query expression.</param>
 public QueryGroup(QueryField queryField,
                   QueryGroup queryGroup) :
     this(queryField?.AsEnumerable(),
          queryGroup?.AsEnumerable(),
          Conjunction.And,
          false)
 {
 }
Пример #4
0
        /** QueryField / QueryGroups **/

        /// <summary>
        /// Creates a new instance of <see cref="QueryGroup"/> object.
        /// </summary>
        /// <param name="queryField">The field to be grouped for the query expression.</param>
        /// <param name="queryGroups">The child query groups to be grouped for the query expression.</param>
        public QueryGroup(QueryField queryField,
                          IEnumerable <QueryGroup> queryGroups) :
            this(queryField?.AsEnumerable(),
                 queryGroups,
                 Conjunction.And,
                 false)
        {
        }
Пример #5
0
 /// <summary>
 /// Creates a new instance of <see cref="QueryGroup"/> object.
 /// </summary>
 /// <param name="queryField">The field to be grouped for the query expression.</param>
 /// <param name="queryGroup">The child query group to be grouped for the query expression.</param>
 /// <param name="isNot">The prefix to be added whether the field value is in opposite state.</param>
 public QueryGroup(QueryField queryField,
                   QueryGroup queryGroup,
                   bool isNot) :
     this(queryField?.AsEnumerable(),
          queryGroup?.AsEnumerable(),
          Conjunction.And,
          isNot)
 {
 }
Пример #6
0
        /** QueryField / QueryGroup **/

        /// <summary>
        /// Creates a new instance of <see cref="QueryGroup"/> object.
        /// </summary>
        /// <param name="queryField">The field to be grouped for the query expression.</param>
        /// <param name="queryGroup">The child query group to be grouped for the query expression.</param>
        /// <param name="conjunction">The conjunction to be used for every group separation.</param>
        public QueryGroup(QueryField queryField,
                          QueryGroup queryGroup,
                          Conjunction conjunction) :
            this(queryField?.AsEnumerable(),
                 queryGroup?.AsEnumerable(),
                 conjunction,
                 false)
        {
        }
Пример #7
0
 /// <summary>
 /// Creates a new instance of <see cref="QueryGroup"/> object.
 /// </summary>
 /// <param name="queryField">The field to be grouped for the query expression.</param>
 /// <param name="queryGroups">The child query groups to be grouped for the query expression.</param>
 /// <param name="conjunction">The conjunction to be used for every group separation.</param>
 /// <param name="isNot">The prefix to be added whether the field value is in opposite state.</param>
 public QueryGroup(QueryField queryField,
                   IEnumerable <QueryGroup> queryGroups,
                   Conjunction conjunction,
                   bool isNot) :
     this(queryField?.AsEnumerable(),
          queryGroups,
          conjunction,
          isNot)
 {
 }
Пример #8
0
        private static QueryGroup Parse <TEntity>(MemberExpression expression, ExpressionType expressionType, bool isNot = false, bool isEqualsTo = true) where TEntity : class
        {
            var queryGroup = (QueryGroup)null;
            var value      = expression.GetValue();

            if (value != null)
            {
                var field = new QueryField(expression.Member.GetMappedName(), QueryField.GetOperation(expressionType), value);
                queryGroup = new QueryGroup(field.AsEnumerable());
                queryGroup.SetIsNot(isEqualsTo == false);
            }
            return(queryGroup);
        }
Пример #9
0
        private static QueryGroup ParseContainsForArray <TEntity>(MethodCallExpression expression, bool isNot, bool isEqualsTo = true) where TEntity : class
        {
            // Return null if there is no any arguments
            if (expression.Arguments?.Any() == false)
            {
                return(null);
            }

            // Get the last arg
            var last = expression
                       .Arguments
                       .LastOrDefault();

            // Make sure the last arg is a member
            if (last == null || last?.IsMember() == false)
            {
                throw new NotSupportedException($"Expression '{expression.ToString()}' is currently not supported.");
            }

            // Make sure it is a property info
            var member = last.ToMember().Member;

            if (member.IsPropertyInfo() == false)
            {
                throw new NotSupportedException($"Expression '{expression.ToString()}' is currently not supported.");
            }

            // Get the property
            var property = member.ToPropertyInfo();

            // Make sure the property is in the entity
            if (PropertyCache.Get <TEntity>().FirstOrDefault(p => p.PropertyInfo == property) == null)
            {
                throw new InvalidQueryExpressionException($"Invalid expression '{expression.ToString()}'. The property {property.Name} is not defined on a target type '{typeof(TEntity).FullName}'.");
            }

            // Get the values
            var values = expression.Arguments.First().GetValue();

            // Add to query fields
            var operation  = isNot ? Operation.NotIn : Operation.In;
            var queryField = new QueryField(property.Name, operation, values);

            // Return the result
            var queryGroup = new QueryGroup(queryField.AsEnumerable());

            queryGroup.SetIsNot(isEqualsTo == false);
            return(queryGroup);
        }
Пример #10
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="expression"></param>
        /// <param name="isNot"></param>
        /// <param name="isEqualsTo"></param>
        /// <returns></returns>
        private static QueryGroup ParseContainsOrStartsWithOrEndsWithForStringProperty <TEntity>(MethodCallExpression expression,
                                                                                                 bool isNot,
                                                                                                 bool isEqualsTo)
            where TEntity : class
        {
            // TODO: Refactor this

            // Return null if there is no any arguments
            if (expression.Arguments?.Any() != true)
            {
                return(null);
            }

            // Get the value arg
            var value = Convert.ToString(expression.Arguments.FirstOrDefault()?.GetValue());

            // Make sure it has a value
            if (string.IsNullOrWhiteSpace(value))
            {
                throw new NotSupportedException($"Expression '{expression.ToString()}' is currently not supported.");
            }

            // Make sure it is a property info
            var member = expression.Object.ToMember().Member;

            if (member.IsPropertyInfo() == false)
            {
                throw new NotSupportedException($"Expression '{expression.ToString()}' is currently not supported.");
            }

            // Get the property
            var property = member.ToPropertyInfo();

            // Make sure the property is in the entity
            if (PropertyCache.Get <TEntity>().FirstOrDefault(p => string.Equals(p.PropertyInfo.Name, property.Name, StringComparison.OrdinalIgnoreCase)) == null)
            {
                throw new InvalidExpressionException($"Invalid expression '{expression.ToString()}'. The property {property.Name} is not defined on a target type '{typeof(TEntity).FullName}'.");
            }

            // Add to query fields
            var operation  = (isNot == isEqualsTo) ? Operation.NotLike : Operation.Like;
            var queryField = new QueryField(PropertyMappedNameCache.Get(property),
                                            operation,
                                            ConvertToLikeableValue(expression.Method.Name, value));

            // Return the result
            return(new QueryGroup(queryField.AsEnumerable()));
        }