Skip to content

Commit

Permalink
Use Not instead of Negate for network/fulltext
Browse files Browse the repository at this point in the history
Fixes #1118
  • Loading branch information
roji committed Feb 3, 2020
1 parent 29c6822 commit 4b39e33
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,8 @@ public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadO
nameof(NpgsqlFullTextSearchLinqExtensions.And) => QueryReturningOnTwoQueries("&&"),
nameof(NpgsqlFullTextSearchLinqExtensions.Or) => QueryReturningOnTwoQueries("||"),

// TODO: Hack, see #1118
nameof(NpgsqlFullTextSearchLinqExtensions.ToNegative)
=> new SqlUnaryExpression(ExpressionType.Negate, arguments[0], arguments[0].Type, arguments[0].TypeMapping),
=> new SqlUnaryExpression(ExpressionType.Not, arguments[0], arguments[0].Type, arguments[0].TypeMapping),

nameof(NpgsqlFullTextSearchLinqExtensions.Contains) => BoolReturningOnTwoQueries("@>"),
nameof(NpgsqlFullTextSearchLinqExtensions.IsContainedIn) => BoolReturningOnTwoQueries("<@"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadO
nameof(NpgsqlNetworkExtensions.ContainsOrEqual) => BoolReturningOnTwoNetworkTypes(">>="),
nameof(NpgsqlNetworkExtensions.ContainsOrContainedBy) => BoolReturningOnTwoNetworkTypes("&&"),

// TODO: Hack, see #1118
nameof(NpgsqlNetworkExtensions.BitwiseNot) => new SqlUnaryExpression(ExpressionType.Negate,
nameof(NpgsqlNetworkExtensions.BitwiseNot) => new SqlUnaryExpression(ExpressionType.Not,
arguments[1],
arguments[1].Type,
arguments[1].TypeMapping),
Expand Down
8 changes: 3 additions & 5 deletions src/EFCore.PG/Query/Internal/NpgsqlQuerySqlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,18 +193,16 @@ protected override Expression VisitSqlUnary(SqlUnaryExpression sqlUnaryExpressio
}

// Bitwise complement on networking types
// TODO: Hack, see #1118
case ExpressionType.Negate when
case ExpressionType.Not when
sqlUnaryExpression.Operand.TypeMapping.ClrType == typeof(IPAddress) ||
sqlUnaryExpression.Operand.TypeMapping.ClrType == typeof((IPAddress, int)) ||
sqlUnaryExpression.Operand.TypeMapping.ClrType == typeof(PhysicalAddress):
Sql.Append('~');
Visit(sqlUnaryExpression.Operand);
return sqlUnaryExpression;

// Negation on full-text queries
// TODO: Hack, see #1118
case ExpressionType.Negate when sqlUnaryExpression.Operand.TypeMapping.ClrType == typeof(NpgsqlTsQuery):
// Not operation on full-text queries
case ExpressionType.Not when sqlUnaryExpression.Operand.TypeMapping.ClrType == typeof(NpgsqlTsQuery):
Sql.Append("!!");
Visit(sqlUnaryExpression.Operand);
return sqlUnaryExpression;
Expand Down

0 comments on commit 4b39e33

Please sign in to comment.