Skip to content

Translation for Nullable<T>.ToString() #33942

Closed
Closed

Description

@ranma42

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 with NULL
  • EFCore returns NULL for NULLs in bool? columns in SQL Server and Sqlite
  • EFCore returns the "True" string for NULL in other bool? expressions
    reported as Inconsistent results for Nullable<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

  1. roji commented on Jun 14, 2024

    @roji
    Member

    @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.

  2. roji commented on Jun 17, 2024

    @roji
    Member

    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.

  3. ranma42 commented on Jul 16, 2024

    @ranma42
    ContributorAuthor
  4. added this to the 9.0.0 milestone on Jul 16, 2024
  5. maumar commented on Jul 16, 2024

    @maumar
    Contributor

    We can do the documentation note later, I filed an issue to track this - dotnet/EntityFramework.Docs#4765

  6. maumar commented on Jul 16, 2024

    @maumar
    Contributor

    fixed by @ranma42 in ef5693f and 61bb028

  7. 4 remaining items

  8. added this to the milestone on Aug 21, 2024
  9. modified the milestones: , 9.0.0 on Oct 12, 2024
  10. added theissue type on Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions