-
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
'Nullable object must have a value' with bool? value == true #14040
Comments
Possibly related #13908 |
Do you have any solution or workaround for this problem ? |
@alpergunay As I stated above, changing the syntax a bit does produce the correct result, but it is less intuitive in my opinion. Instead of |
I'm having the same issue, but with a non-nullable value. var firstSelect = query.Select(s=>new {Quantity = ..., Requested = ...}); Quantity and Requested are non nullable int, and the same exception happens. If I remove s.Requested it works. I can't send the entire code now, which is company's, but later today I'll try to make a reproducible example. By the way, I'm using Castle Proxies, which is also one of my suspects. |
@iamdroppy - Which version of EF Core are you using? |
@smitpatel I'm on .NET Core 2.2. I'm confident this may be an issue with Castle Proxy. I've got a table which is like this (of course, just this column):
LINQ on Returns: entire table (correct) Now, I've done two more tests:
and then I tried This is regarding the issue that I've commented above. I have refactored to use one Select and it worked, but it stills make me wonder why. P.S: this exception happens on non-nullable data, and in this post I'm just mentioning something awkward that also happened with the same query, because if I setted the breakpoint it would show the data, so I'd guess something with Lazy Loading proxies. But why P.S.S: I appologise for not have sent a working snippet, as I still have to reproduce in a non-company code, and I haven't got time this week yet. csproj packages:
Maybe it's better if I open another issue. |
@iamdroppy - Please file a new issue with repro code so we can investigate. |
When I do a select against a nullable bool, the translated SQL doesn't match.
Steps to reproduce
Consider the following query. Note that the dto's IsPendingConfirmation is of type bool, while siteAccount.IsLocked is of type bool?.
which generates the following sql
This sql is wrong because it can return null responses for IsPendingConfirmation even though 'siteAccount.IsLocked == true' should never be able to return null. When null is returned, it then results in the "nullable object' exception.
Note that changing to 'IsPendingConfirmation = siteAccount.IsLocked ?? false,' does produce the correct sql: CAST(COALESCE([siteAccount].[bitLocked], 0) AS bit) AS [IsPendingConfirmation]. I've used 'bool? == true' constructs all over the place, and this works fine in EF.
Further technical details
EF Core version: 2.1.4
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10
IDE: Visual Studio 2017 15.9.2
The text was updated successfully, but these errors were encountered: