private SqlExpression ApplyTypeMappingOnSqlUnary( SqlUnaryExpression sqlUnaryExpression, CoreTypeMapping typeMapping) { SqlExpression operand; CoreTypeMapping resultTypeMapping; switch (sqlUnaryExpression.OperatorType) { case ExpressionType.Equal: case ExpressionType.NotEqual: case ExpressionType.Not: resultTypeMapping = _boolTypeMapping; operand = ApplyDefaultTypeMapping(sqlUnaryExpression.Operand); break; case ExpressionType.Convert: resultTypeMapping = typeMapping; operand = ApplyDefaultTypeMapping(sqlUnaryExpression.Operand); break; case ExpressionType.Negate: resultTypeMapping = typeMapping; operand = ApplyTypeMapping(sqlUnaryExpression.Operand, typeMapping); break; default: throw new InvalidOperationException(); } return(new SqlUnaryExpression( sqlUnaryExpression.OperatorType, operand, sqlUnaryExpression.Type, resultTypeMapping)); }
private SqlExpression ApplyTypeMappingOnSqlUnary( SqlUnaryExpression sqlUnaryExpression, CoreTypeMapping typeMapping) { SqlExpression operand; Type resultType; CoreTypeMapping resultTypeMapping; switch (sqlUnaryExpression.OperatorType) { case ExpressionType.Equal: case ExpressionType.NotEqual: case ExpressionType.Not when sqlUnaryExpression.IsLogicalNot(): { resultTypeMapping = _boolTypeMapping; resultType = typeof(bool); operand = ApplyDefaultTypeMapping(sqlUnaryExpression.Operand); break; } case ExpressionType.Convert: resultTypeMapping = typeMapping; // Since we are applying convert, resultTypeMapping decides the clrType resultType = resultTypeMapping?.ClrType ?? sqlUnaryExpression.Type; operand = ApplyDefaultTypeMapping(sqlUnaryExpression.Operand); break; case ExpressionType.Not: case ExpressionType.Negate: resultTypeMapping = typeMapping; // While Not is logical, negate is numeric hence we use clrType from TypeMapping resultType = resultTypeMapping?.ClrType ?? sqlUnaryExpression.Type; operand = ApplyTypeMapping(sqlUnaryExpression.Operand, typeMapping); break; default: throw new InvalidOperationException( CosmosStrings.UnsupportedOperatorForSqlExpression( sqlUnaryExpression.OperatorType, typeof(SqlUnaryExpression).ShortDisplayName())); ; } return(new SqlUnaryExpression(sqlUnaryExpression.OperatorType, operand, resultType, resultTypeMapping)); }
/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> protected override Expression VisitSqlUnary(SqlUnaryExpression sqlUnaryExpression) { var op = _operatorMap[sqlUnaryExpression.OperatorType]; if (sqlUnaryExpression.OperatorType == ExpressionType.Not && sqlUnaryExpression.Operand.Type == typeof(bool)) { op = "NOT"; } _sqlBuilder.Append(op); _sqlBuilder.Append("("); Visit(sqlUnaryExpression.Operand); _sqlBuilder.Append(")"); return(sqlUnaryExpression); }
private SqlExpression ApplyTypeMappingOnSqlUnary( SqlUnaryExpression sqlUnaryExpression, CoreTypeMapping typeMapping) { SqlExpression operand; CoreTypeMapping resultTypeMapping; switch (sqlUnaryExpression.OperatorType) { case ExpressionType.Equal: case ExpressionType.NotEqual: case ExpressionType.Not when sqlUnaryExpression.IsLogicalNot(): { resultTypeMapping = _boolTypeMapping; operand = ApplyDefaultTypeMapping(sqlUnaryExpression.Operand); break; } case ExpressionType.Convert: resultTypeMapping = typeMapping; operand = ApplyDefaultTypeMapping(sqlUnaryExpression.Operand); break; case ExpressionType.Not: case ExpressionType.Negate: resultTypeMapping = typeMapping; operand = ApplyTypeMapping(sqlUnaryExpression.Operand, typeMapping); break; default: throw new InvalidOperationException(CoreStrings.TranslationFailed(sqlUnaryExpression.Print())); } return(new SqlUnaryExpression( sqlUnaryExpression.OperatorType, operand, sqlUnaryExpression.Type, resultTypeMapping)); }
/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> protected abstract Expression VisitSqlUnary(SqlUnaryExpression sqlUnaryExpression);
protected abstract Expression VisitSqlUnary([NotNull] SqlUnaryExpression sqlUnaryExpression);