Consider allowing unmapped enums to be written as int/string · Issue #3303 · npgsql/npgsql · GitHub
Skip to content

Consider allowing unmapped enums to be written as int/string #3303

Description

@roji

@mikependon did a lot of comparative work on enum coercion across ADO.NET providers (thanks @mikependon!) - the results can be seen here: https://twitter.com/mike_pendon/status/1325442299862659074.

Bottom line:

  • When DbType.String or DbType.Integer are set, enums are properly coerced by all providers except Npgsql
  • When DbType isn't set, some inconsistent behavior occurs, e.g. the int value would be textually saved in text columns in some cases.

I don't think we should support this without DbType (especially in light of the weird/problematic behavior across providers), but we should consider aligning with others and at least allowing DbType.String/Integer.

Activity

  1. added this to the vNext milestone on Nov 8, 2020
  2. mikependon commented on Dec 13, 2020

    @mikependon

    @roji never saw this on the latest release, when do think is the timeline of this? I am asking due to our internal schedule of RepoDB's release, maybe we can include the changes to this as well if necessary.

  3. YohDeadfall commented on Dec 13, 2020

    @YohDeadfall
    Contributor

    #3389 changed the behaviour of the driver by allowing writing of unmapped enum without setting up a command parameter.

  4. roji commented on Dec 13, 2020

    @roji
    MemberAuthor

    @mikependon @YohDeadfall note that #3389 is quite different from this. #3389 is about allowing sending CLR enums to PostgreSQL enums, without mapping them beforehand. This issue is about allowing coercing CLR enums to PG int/text by using DbType.

  5. mikependon commented on Dec 13, 2020

    @mikependon

    @roji - thanks, I am about to test it actually. Anyway, I will just wait for the fix for this one then, before doing the changes on our compiler. Do you have the timeline for this?

  6. roji commented on Dec 13, 2020

    @roji
    MemberAuthor

    I'm not sure this is something we'll patch, so it'll probably only be out in the next version, which is probably months away (we just released 5.0).

  7. modified the milestones: 6.0.0, 7.0.0 on Oct 3, 2021
  8. modified the milestones: 7.0.0, 8.0.0 on Nov 1, 2022
  9. self-assigned this
    on Dec 28, 2022
  10. modified the milestones: 8.0.0, 9.0.0 on Nov 15, 2023
  11. modified the milestones: 9.0.0, 10.0.0 on Nov 18, 2024
  12. added theissue type on Jun 14, 2025
  13. modified the milestones: 10.0.0, 11.0.0 on Oct 1, 2025
  14. NinoFloris commented on Apr 21, 2026

    @NinoFloris
    Member

    Most of this can be made to work quite nicely on .NET 10 once #6317 is merged. Though full support for all our array mappings (List<T> and any future types applied to all array mappings) must always require an explicit registration.

    TEnum[] (and multidim cases) will work without explicit registration due to how NAOT handles array types in special ways. Read requests for interfaces implemented by TEnum[] today don't quite work though. I've opened a runtime issue about this here: dotnet/runtime#127249.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions