Closed
Description
What is the intended translation for Nullable<T>.ToString()?
It is currently unclear (at least to me) what is the intended result (and/or translation) because:
- the C# documentation states that it returns
The text representation of the value of the current Nullable object if the HasValue property is true, or an empty string ("") if the HasValue property is false.
- EFCore is attempting to test that the translation matches the C# definition in
ToString_boolean_property_nullable, but it does so without ever populating the column withNULL - EFCore returns
NULLforNULLs inbool?columns in SQL Server and Sqlite - EFCore returns the
"True"string forNULLin otherbool?expressions
reported as Inconsistent results forNullable<bool>.ToString()#33941 - EFCore returns
""for enums - EFCore converts (hence propagates
NULL) for several types in SQL Server and Sqlite
I realized that the situation was unclear while working on #33940
Activity
roji commentedon Jun 14, 2024
@ranma42 thanks for digging into this, the current situation indeed seems quite problematic.
Without going into specifics, we'd ideally align the translation with the .NET behavior, which as you say is to return an empty string; this would be a small breaking change, but one which I think would be accepted (as the current behavior is simply buggy). I'll bring this up in a design discussion to make sure the team agrees.
roji commentedon Jun 17, 2024
Design discussion: we agree that we should align the Nullable ToString() behavior to the .NET one in all cases (empty string); although this is a breaking change, we consider it a minor one, and the current behavior is buggy.
ranma42 commentedon Jul 16, 2024
This should now be fixed in the codebase. Given that it is a breaking change, should it be mentioned in https://github.com/dotnet/EntityFramework.Docs/blob/main/entity-framework/core/what-is-new/ef-core-9.0/breaking-changes.md before closing?
maumar commentedon Jul 16, 2024
We can do the documentation note later, I filed an issue to track this - dotnet/EntityFramework.Docs#4765
maumar commentedon Jul 16, 2024
fixed by @ranma42 in ef5693f and 61bb028
4 remaining items
- Whats new in EF9 docs
- Whats new in EF9 docs
- Whats new in EF9 docs
- Whats new in EF9 docs
- Whats new in EF9 docs
- Whats new in EF9 docs
- Whats new in EF9 docs
- Whats new in EF9 docs
- Whats new in EF9 docs
- Whats new in EF9 docs (#4823)