You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Make annotations available in TypeMappingInfo #14000
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.
@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
Activity
ajcvickers commentedon Nov 26, 2018
@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
AndriySvyryd commentedon Nov 26, 2018
All non-excluded annotations should be in the snapshot already, so we would only need to add them to the
TypeMappingInfo[-]Make IProperty available in TypeMappingInfo[/-][+]Make annotations available in TypeMappingInfo[/+]