-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SqlServer never returns null
for nullable Boolean expressions
#34001
Comments
Some specific |
null
for bool?
expressionsnull
for nullable Boolean expressions
When neither the parent expression nor the inner one is a predicate, translate to: ```sql x ^ CAST(1 AS bit) ``` instead of ```sql CASE WHEN x = CAST(0 AS bit) THEN CAST(1 AS bit) ELSE CAST(0 AS bit) END ``` Contributes to dotnet#34001 for simple cases (NOT of BIT expressions).
When neither the parent expression nor the inner one is a predicate, translate to: ```sql x ^ CAST(1 AS bit) ``` instead of ```sql CASE WHEN x = CAST(0 AS bit) THEN CAST(1 AS bit) ELSE CAST(0 AS bit) END ``` Contributes to dotnet#34001 for simple cases (NOT of BIT expressions).
Use `XOR` to translate some `NOT` expressions When neither the parent expression nor the inner one is a predicate, translate to: ```sql x ^ CAST(1 AS bit) ``` instead of ```sql CASE WHEN x = CAST(0 AS bit) THEN CAST(1 AS bit) ELSE CAST(0 AS bit) END ``` Contributes to #34001 for simple cases (NOT of BIT expressions).
When the parent expression is not a predicate, translate `x != y` to: ```sql x ^ y ``` instead of ```sql CASE WHEN x <> y THEN CAST(1 AS bit) ELSE CAST(0 AS bit) END ``` Similarly, translate `x == y` to: ```sql x ^ y ^ CAST(1 AS bit) ``` instead of ```sql CASE WHEN x == y THEN CAST(1 AS bit) ELSE CAST(0 AS bit) END ``` Contributes to dotnet#34001 for simple cases (comparison of BIT expressions).
When the parent expression is not a predicate, translate `x != y` to: ```sql x ^ y ``` instead of ```sql CASE WHEN x <> y THEN CAST(1 AS bit) ELSE CAST(0 AS bit) END ``` Similarly, translate `x == y` to: ```sql x ^ y ^ CAST(1 AS bit) ``` instead of ```sql CASE WHEN x == y THEN CAST(1 AS bit) ELSE CAST(0 AS bit) END ``` Contributes to dotnet#34001 for simple cases (comparison of BIT expressions).
When the parent expression is not a predicate, translate `x != y` to: ```sql x ^ y ``` instead of ```sql CASE WHEN x <> y THEN CAST(1 AS bit) ELSE CAST(0 AS bit) END ``` Similarly, translate `x == y` to: ```sql x ^ y ^ CAST(1 AS bit) ``` instead of ```sql CASE WHEN x == y THEN CAST(1 AS bit) ELSE CAST(0 AS bit) END ``` Contributes to dotnet#34001 for simple cases (comparison of BIT expressions).
* Use XOR to translate some `==` and `!=` expressions When the parent expression is not a predicate, translate `x != y` to: ```sql x ^ y ``` instead of ```sql CASE WHEN x <> y THEN CAST(1 AS bit) ELSE CAST(0 AS bit) END ``` Similarly, translate `x == y` to: ```sql x ^ y ^ CAST(1 AS bit) ``` instead of ```sql CASE WHEN x == y THEN CAST(1 AS bit) ELSE CAST(0 AS bit) END ``` Contributes to #34001 for simple cases (comparison of BIT expressions).
I am investigating the possible translations. Currently the best candidate for an expression CASE
WHEN x IS NULL THEN NULL
WHEN x THEN CAST(1 AS bit)
ELSE CAST(0 AS bit)
END The main advantage of this translation is that (as long as appropriate simplifications are performed), |
When the parent expression is not a predicate, translate `x != y` to: ```sql CAST(x ^ y AS BIT) ``` instead of ```sql CASE WHEN x <> y THEN CAST(1 AS bit) ELSE CAST(0 AS bit) END ``` Similarly, translate `x == y` to: ```sql CAST(x ^ y AS BIT) ^ CAST(1 AS bit) ``` instead of ```sql CASE WHEN x == y THEN CAST(1 AS bit) ELSE CAST(0 AS bit) END ``` Contributes to dotnet#34001.
When the parent expression is not a predicate, translate `x != y` to: ```sql CAST(x ^ y AS BIT) ``` instead of ```sql CASE WHEN x <> y THEN CAST(1 AS bit) ELSE CAST(0 AS bit) END ``` Similarly, translate `x == y` to: ```sql CAST(x ^ y AS BIT) ^ CAST(1 AS bit) ``` instead of ```sql CASE WHEN x == y THEN CAST(1 AS bit) ELSE CAST(0 AS bit) END ``` Contributes to dotnet#34001.
* Use XOR to translate some == and != expressions When the parent expression is not a predicate, translate `x != y` to: ```sql CAST(x ^ y AS BIT) ``` instead of ```sql CASE WHEN x <> y THEN CAST(1 AS bit) ELSE CAST(0 AS bit) END ``` Similarly, translate `x == y` to: ```sql CAST(x ^ y AS BIT) ^ CAST(1 AS bit) ``` instead of ```sql CASE WHEN x == y THEN CAST(1 AS bit) ELSE CAST(0 AS bit) END ``` Contributes to #34001
The SqlServer provider never returns
null
forbool?
expressions; instead it returnsfalse
.An example program that showcases the bug is:
The query is translated to
hence the result of the
SELECT
can only be0
or1
(this also happens by actually performing the query; in that case it obviously requires a running instance of SqlServer).Include provider and version information
EF Core version: 8.0.6
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 8.0
Operating system: Linux (/WSL)
IDE: Visual Studio Code 1.89.1
The text was updated successfully, but these errors were encountered: