Decided to take a trip down the rabbit hole.
https://github.com/efcore/EFCore.SqlServer.HierarchyId/
Adds a type HierarchyId to typeMappingSource and utilizes a value converter to convert it to provider clr type of SqlBytes.
When populating HasData and generating Snapshot,
- We use the provider clr type from the value converter rather than using
HierarchyId, this in turn creates properties of SqlBytes in the model. (we add using statement so this part works ok).
- Getting seed data converts
HierarchyId values to SqlBytes values and now we try to print SqlBytes values in the snapshot.
- The printing part is not aware of the actual type mapping from property which had value converter. So it tries to find type mapping for
SqlBytes which of course does not exist hence we throw exception.
Same also exists for our own Geometry types in NTS packages.
The way both code had "work-around" is, have a ValueConverter but not let EF know about it so EF Core will have HierarchyId everywhere, this eventually invokes GenerateCodeLiteral on HierarchyIdTypeMapping which can print out literal. And whenever methods on HierarchyIdTypeMapping are invoked use the value converter.
Decided to take a trip down the rabbit hole.
https://github.com/efcore/EFCore.SqlServer.HierarchyId/
Adds a type
HierarchyIdto typeMappingSource and utilizes a value converter to convert it to provider clr type ofSqlBytes.When populating HasData and generating Snapshot,
HierarchyId, this in turn creates properties ofSqlBytesin the model. (we add using statement so this part works ok).HierarchyIdvalues toSqlBytesvalues and now we try to printSqlBytesvalues in the snapshot.SqlByteswhich of course does not exist hence we throw exception.Same also exists for our own Geometry types in NTS packages.
The way both code had "work-around" is, have a ValueConverter but not let EF know about it so EF Core will have HierarchyId everywhere, this eventually invokes GenerateCodeLiteral on HierarchyIdTypeMapping which can print out literal. And whenever methods on HierarchyIdTypeMapping are invoked use the value converter.