void DefinePredicate(IComparisonOperator op, BinaryExpression X) { if (!SpecifiesMemberPredicate(X)) { return; } var member = X.TryGetAccessedMember(); if (!member) { return; } var value = X.GetValue(); if (!value) { return; } var predicate = MemberValuePredicate.Define(op, member.Require(), value.Require()); if (CurrentJunction != null) { CurrentJunction.Item2.Criteria.Add(predicate); } }
// Static Methods #region Parse (Expression) /// <summary> /// Parse an instance of <see cref="BinaryExpression"/> object. /// </summary> /// <typeparam name="TEntity">The target entity type</typeparam> /// <param name="expression">The instance of <see cref="BinaryExpression"/> to be parsed.</param> /// <returns>An instance of <see cref="QueryField"/> object.</returns> internal static QueryField Parse <TEntity>(BinaryExpression expression) where TEntity : class { // Only support the following expression type if (expression.IsExtractable() == false) { throw new NotSupportedException($"Expression '{expression.ToString()}' is currently not supported."); } // Name var fieldName = expression.GetName(); if (PropertyCache.Get <TEntity>(Command.None).Any(property => property.PropertyInfo.Name == fieldName) == false) { throw new InvalidQueryExpressionException($"Invalid expression '{expression.ToString()}'. The property {fieldName} is not defined on a target type '{typeof(TEntity).FullName}'."); } // Value var value = expression.GetValue(); // Operation var operation = GetOperation(expression.NodeType); // Return the value return(new QueryField(fieldName, operation, value)); }
/// <summary> /// Parse an instance of <see cref="BinaryExpression"/> object. /// </summary> /// <typeparam name="TEntity">The target entity type</typeparam> /// <param name="expression">The instance of <see cref="BinaryExpression"/> to be parsed.</param> /// <returns>An instance of <see cref="QueryField"/> object.</returns> internal static QueryField Parse <TEntity>(BinaryExpression expression) where TEntity : class { // Only support the following expression type if (expression.IsExtractable() == false) { throw new NotSupportedException($"Expression '{expression}' is currently not supported."); } // Field var field = expression.GetField(); var property = GetTargetProperty <TEntity>(field); // Check if (property == null) { throw new InvalidExpressionException($"Invalid expression '{expression}'. The property {field.Name} is not defined on a target type '{typeof(TEntity).FullName}'."); } else { field = property.AsField(); } // Value var value = expression.GetValue(); // Operation var operation = GetOperation(expression.NodeType); // Return the value return(new QueryField(field, operation, value)); }
/// <summary> /// Parse an instance of <see cref="BinaryExpression"/> object. /// </summary> /// <typeparam name="TEntity">The target entity type</typeparam> /// <param name="expression">The instance of <see cref="BinaryExpression"/> to be parsed.</param> /// <returns>An instance of <see cref="QueryField"/> object.</returns> internal static QueryField Parse <TEntity>(BinaryExpression expression) where TEntity : class { // Only support the following expression type if (expression.IsExtractable() == false) { throw new NotSupportedException($"Expression '{expression.ToString()}' is currently not supported."); } // Name var field = expression.GetField(); var properties = PropertyCache.Get <TEntity>(); // Failing at some point - for base interfaces var property = properties .FirstOrDefault(p => string.Equals(PropertyMappedNameCache.Get(p.PropertyInfo), field.Name, StringComparison.OrdinalIgnoreCase)); // Matches to the actual class properties if (property == null) { property = properties .FirstOrDefault(p => string.Equals(p.PropertyInfo.Name, field.Name, StringComparison.OrdinalIgnoreCase)); // Reset the field field = property?.AsField(); } // Check the existence if (property == null) { throw new InvalidExpressionException($"Invalid expression '{expression.ToString()}'. The property {field.Name} is not defined on a target type '{typeof(TEntity).FullName}'."); } // Value var value = expression.GetValue(); // Operation var operation = GetOperation(expression.NodeType); // Return the value return(new QueryField(field, operation, value)); }