Skip to content

Make annotations available in TypeMappingInfo #14000

Description

@roji

When constructed from an IProperty, TypeMappingInfo currently extracts various information from it (e.g. ClrType), but does not keep the IProperty itself. This makes it impossible for the type mapper to access any annotations applied to the property which could influence the mapping.

For a concrete example, PostgreSQL PostGIS supports the following store type: GEOMETRY (POINT,4326). This acts as a constraint on the column to only accept points with SRID 4326. Now, we can add ForNpgsqlHasSrid() extension method just like Sqlite, but we have no way to flow this information into Npgsql's relational type mapping, to make it construct the right store type string.

As a workaround, I can catch this annotation in my MigrationsSqlGenerator, take the partial store type given by the mapping, and patch it to contain the SRID. However, this really seems like a hack (not to mention that spatial support is implemented in a plugin and MigrationsSqlGenerator is part of the provider). If the mapping could access the annotation, it would be able to generate a complete store type and this wouldn't be needed.

/cc @austindrenski

Activity

  1. ajcvickers commented on Nov 26, 2018

    @ajcvickers
    Contributor

    @roji The general problem here is that we need to be able to build the same type mapping from the model snapshot as was built originally. If we store and expose the IProperty, then providers will use this in the type mapping process--as you are asking for--but then we won't be able to reliably re-create it from the model snapshot, resulting in a different type mapping and a bogus migration. So it's possible that we need to make the property annotations available and at the same time make sure those annotations make it into the snapshot.
    /cc @AndriySvyryd @bricelam

  2. AndriySvyryd commented on Nov 26, 2018

    @AndriySvyryd
    Member

    All non-excluded annotations should be in the snapshot already, so we would only need to add them to the TypeMappingInfo

  3. self-assigned this
    on Nov 28, 2018
  4. added this to the 3.0.0 milestone on Nov 28, 2018
  5. modified the milestones: 3.0.0, Backlog on Jun 28, 2019
  6. changed the title [-]Make IProperty available in TypeMappingInfo[/-] [+]Make annotations available in TypeMappingInfo[/+] on Oct 20, 2022
  7. removed their assignment
    on Aug 31, 2024
  8. 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

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions