public virtual SqlConditionalExpression Condition(SqlExpression test, SqlExpression ifTrue, SqlExpression ifFalse) { var typeMapping = ExpressionExtensions.InferTypeMapping(ifTrue, ifFalse); return(new SqlConditionalExpression( ApplyTypeMapping(test, _boolTypeMapping), ApplyTypeMapping(ifTrue, typeMapping), ApplyTypeMapping(ifFalse, typeMapping))); }
private SqlExpression ApplyTypeMappingOnSqlBinary( SqlBinaryExpression sqlBinaryExpression, CoreTypeMapping?typeMapping) { var left = sqlBinaryExpression.Left; var right = sqlBinaryExpression.Right; Type resultType; CoreTypeMapping resultTypeMapping; CoreTypeMapping 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.LeftShift: case ExpressionType.RightShift: 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)); }