Esempio n. 1
0
        private SqlExpression ApplyTypeMappingOnLike(LikeExpression likeExpression)
        {
            var inferredTypeMapping = ExpressionExtensions.InferTypeMapping(
                likeExpression.Match, likeExpression.Pattern, likeExpression.EscapeChar)
                                      ?? _typeMappingSource.FindMapping(likeExpression.Match.Type);

            return(new LikeExpression(
                       ApplyTypeMapping(likeExpression.Match, inferredTypeMapping),
                       ApplyTypeMapping(likeExpression.Pattern, inferredTypeMapping),
                       ApplyTypeMapping(likeExpression.EscapeChar, inferredTypeMapping),
                       _boolTypeMapping));
        }
Esempio n. 2
0
        private SqlExpression ApplyTypeMappingOnSqlBinary(
            SqlBinaryExpression sqlBinaryExpression, RelationalTypeMapping typeMapping)
        {
            var left  = sqlBinaryExpression.Left;
            var right = sqlBinaryExpression.Right;

            Type resultType;
            RelationalTypeMapping resultTypeMapping;
            RelationalTypeMapping inferredTypeMapping;

            switch (sqlBinaryExpression.OperatorType)
            {
            case ExpressionType.Equal:
            case ExpressionType.GreaterThan:
            case ExpressionType.GreaterThanOrEqual:
            case ExpressionType.LessThan:
            case ExpressionType.LessThanOrEqual:
            case ExpressionType.NotEqual:
            {
                inferredTypeMapping = ExpressionExtensions.InferTypeMapping(left, right)
                                      ?? _typeMappingSource.FindMapping(left.Type);
                resultType        = typeof(bool);
                resultTypeMapping = _boolTypeMapping;
            }
            break;

            case ExpressionType.AndAlso:
            case ExpressionType.OrElse:
            {
                inferredTypeMapping = _boolTypeMapping;
                resultType          = typeof(bool);
                resultTypeMapping   = _boolTypeMapping;
            }
            break;

            case ExpressionType.Add:
            case ExpressionType.Subtract:
            case ExpressionType.Multiply:
            case ExpressionType.Divide:
            case ExpressionType.Modulo:
            case ExpressionType.Coalesce:
            case ExpressionType.And:
            case ExpressionType.Or:
            {
                inferredTypeMapping = typeMapping ?? ExpressionExtensions.InferTypeMapping(left, right);
                resultType          = left.Type;
                resultTypeMapping   = inferredTypeMapping;
            }
            break;

            default:
                throw new InvalidOperationException("Incorrect operatorType for SqlBinaryExpression");
            }

            return(new SqlBinaryExpression(
                       sqlBinaryExpression.OperatorType,
                       ApplyTypeMapping(left, inferredTypeMapping),
                       ApplyTypeMapping(right, inferredTypeMapping),
                       resultType,
                       resultTypeMapping));
        }