Пример #1
0
        /// <summary>
        /// Generates System.CodeDom.CodeExpression from the given expression.
        /// </summary>
        /// <param name="expression">Expression from which System.CodeDom.CodeExpression is generated.</param>
        /// <returns>Generated System.CodeDom.CodeExpression.</returns>
        public virtual CodeExpression Visit(LinqContainsExpression expression)
        {
            CodeExpression source = this.GenerateCode(expression.Source);
            CodeExpression value  = this.GenerateCode(expression.Value);

            return(source.Call("Contains", value));
        }
Пример #2
0
        /// <summary>
        /// Replaces the given expression.
        /// </summary>
        /// <param name="expression">The root node of the expression tree being visited.</param>
        /// <returns>Replaced expression.</returns>
        public virtual QueryExpression Visit(LinqContainsExpression expression)
        {
            var source = this.ReplaceExpression(expression.Source);
            var value  = this.ReplaceExpression(expression.Value);

            if (this.HasChanged(expression.Source, source) || this.HasChanged(expression.Value, value))
            {
                return(new LinqContainsExpression(source, value, expression.ExpressionType));
            }
            else
            {
                return(expression);
            }
        }
Пример #3
0
        /// <summary>
        /// Evaluates the specified expression.
        /// </summary>
        /// <param name="expression">The expression to evaluate.</param>
        /// <returns>Value of the expression.</returns>
        public QueryValue Visit(LinqContainsExpression expression)
        {
            var source = this.EvaluateCollection(expression.Source);
            var value  = this.Evaluate(expression.Value);

            foreach (var sourceElement in source.Elements)
            {
                var sourceElementStructualValue = sourceElement as QueryStructuralValue;
                var sourceElementReferenceValue = sourceElement as QueryReferenceValue;
                var sourceElementPrimitiveValue = sourceElement as QueryScalarValue;

                QueryScalarValue result;
                if (sourceElementStructualValue != null)
                {
                    var structuralValue = (QueryStructuralValue)value;
                    result = sourceElementStructualValue.EqualTo(structuralValue);
                }
                else if (sourceElementReferenceValue != null)
                {
                    var referenceValue = (QueryReferenceValue)value;
                    result = sourceElementReferenceValue.EqualTo(referenceValue);
                }
                else if (sourceElementPrimitiveValue != null)
                {
                    var primitiveValue = (QueryScalarValue)value;
                    result = sourceElementPrimitiveValue.EqualTo(primitiveValue);

                    // When running someCollection.Contains(null), simple equality comparison is not enough
                    // since the comparison in the evaluation strategy will always return Unknown due to the null
                    // value. In EF the null comparison for the purposes of Contains() will return true if the source
                    // collection has a null element.
                    if (sourceElementPrimitiveValue.IsNull && primitiveValue.IsNull)
                    {
                        result = result.Type.CreateValue(true);
                    }
                }
                else
                {
                    throw new TaupoNotSupportedException("Contains operation on type" + sourceElement.Type.ToString() + " is not supported.");
                }

                if ((bool?)result.Value == true)
                {
                    return(result);
                }
            }

            return(source.Type.EvaluationStrategy.BooleanType.CreateValue(false));
        }
Пример #4
0
        /// <summary>
        /// Resolves types for the specified expression.
        /// </summary>
        /// <param name="expression">The expression to resolve types for.</param>
        /// <returns>Expression with resolved types.</returns>
        public QueryExpression Visit(LinqContainsExpression expression)
        {
            var source     = this.ResolveTypes(expression.Source);
            var value      = this.ResolveTypes(expression.Value);
            var sourceType = ValidateSourceIsACollection(source);

            // For now, only add support for primitive types
            if (sourceType.ElementType is QueryScalarType)
            {
                ExceptionUtilities.Assert(
                    value.ExpressionType is QueryScalarType,
                    "Element type of a source collection is a primitive but the argument is not. They should both be same types.");

                ExceptionUtilities.Assert(
                    ((IQueryClrType)sourceType.ElementType).ClrType.Equals(((IQueryClrType)value.ExpressionType).ClrType),
                    "Type of the argument to contains should be the same as element type of a source collection.");
            }

            return(new LinqContainsExpression(source, value, this.EvaluationStrategy.BooleanType));
        }
Пример #5
0
 /// <summary>
 /// Visits a QueryExpression tree whose root node is the LinqContainsExpression.
 /// </summary>
 /// <param name="expression">The root node of the expression tree being visited.</param>
 /// <returns>Uri query string representing the expression.</returns>
 public virtual string Visit(LinqContainsExpression expression)
 {
     throw new TaupoNotSupportedException("Not supported");
 }