Skip to content

Switch to storing enums as ints in JSON instead of strings #31100

Description

@roji

We currently serialize .NET enums into JSON as their string label; this is:

  1. Incompatible with the behavior of System.Text.Json and Newtonsoft.Json, which serialize to the underlying int value.
  2. Incompatible with our relational behavior, which also value-converts to the int value. This notably means that it's impossible to compare an enum value inside JSON with another enum value outside of JSON in a LINQ query.

Activity

  1. changed the title [-]Switch to storing enums as ints in JSON instead of ints[/-] [+]Switch to storing enums as ints in JSON instead of strings[/+] on Jun 19, 2023
  2. petersladek commented on Jun 28, 2023

    @petersladek

    We ran into this issue - we have json stored in db with enum values as ints. Is there any workaround right now? i.e. possibility of specifying value converter for json property?

  3. ajcvickers commented on Jul 5, 2023

    @ajcvickers
    Contributor

    @petersladek Use HasConversion<int> on the property configuration inside OnModelCreating.`

  4. added this to the 8.0.0 milestone on Jul 7, 2023
  5. added 4 commits that reference this issue on Jul 20, 2023
  6. added 3 commits that reference this issue on Aug 7, 2023
  7. added a commit that references this issue on Aug 10, 2023
  8. modified the milestones: 8.0.0, on Aug 19, 2023
  9. modified the milestones: , 8.0.0 on Nov 14, 2023
  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

Assignees

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions