Skip to content

Remove lookup of JsonTypeMapping via JsonElement #32192

Closed

Description

@roji

In order to find the provider's JsonTypeMapping, our code currently does a standard lookup with CLR type JsonElement (as a sort of special value). The problem is that some provider's actually do support JsonElement as a real property CLR type; in addition, if a user defines a JsonElement property on some entity type, this type mapping will be return, and things will likely fail in some unpredictable way.

We should find another way to look up the JsonTypeMapping, e.g. define some special CLR type instead of JsonElement that could be used, or introduce a new API or something.

/cc @maumar

Activity

  1. maumar commented on Oct 31, 2023

    @maumar
    Contributor

    dummy clr type sounds good to me

  2. added this to the Backlog milestone on Nov 1, 2023
  3. roji commented on Feb 23, 2024

    @roji
    MemberAuthor

    This is unfortunately more than a cleanup - the current hacky way of doing things in EFCore.PG unfortunately doesn't take care of literal generation, which is necessary e.g. when adding a column to an existing table (for the default value). There, CSharpHelper.UnknownLiteral is used, which just does a type mapping lookup based on the CLR type (JsonElement), retrieving the owned JSON type mapping rather than the non-owned one.

    See npgsql/efcore.pg#3107 (comment) for more details.

  4. roji commented on Feb 28, 2025

    @roji
    MemberAuthor

    This also blocks being able to use ToJson() with the PostgreSQL non-default jsonb type (I managed to hack around this for the default jsonb type); see npgsql/efcore.pg#3475 (comment).

    @maumar do you think we can do this for 10?

  5. modified the milestones: Backlog, 10.0.0 on Mar 12, 2025
  6. self-assigned this
    on Mar 12, 2025
  7. added 3 commits that reference this issue on Mar 14, 2025
  8. added a commit that references this issue on Mar 14, 2025
  9. 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

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions