Closed lenardchristopher closed 7 months ago
Researching this a bit more, I think it is a limitation of AutoMapper as a layer on top of the ORM. As far as I know, GetQueryAsync
is using ProjectTo
under the hood. ProjectTo
produces a Queryable with no underlying knowledge of the data schema and doesn't know about anything beyond the base type.
In the mapping profile, IncludeBase
/IncludeAllDerived
only work one way --> exposing the base types mappings to the derived. It would be interesting if there was a way to expose the derived types to the base with attributes similar to JsonDerivedTypeAttribute
.
Anyways, sounds like an issue for AutoMapper instead of this OData extension repo. Probably good to close, but would be interested to hear any thoughts.
Side-effect: I decided TPH just isn't worth it when working with DTOs. Broke everything up.
You might want to include an example to make clear what you think is failing. At at high level I AutoMapper doesn't have any knowledge of a discriminator - not that I know of. AutoMapper will map properties between objects whether or not the ORM treats a property as a discriminator.
It sounds like your question is about mapping derived types rather than the ORMs TPH feature. AutoMapper does support adding derived types to the base mappings. See this example.
Is there support for Descriminators/TPH? When I use an OData query without AutoMapper/ODataQueryOptions, I get back
@odata.type
for my inherited entities. After I switched the DTOs, the responses didn't include type info anymore. Is this a limitation or something I'm doing wrong?Source/destination types
Mapping configuration
Version: x.y.z
Expected behavior
Actual behavior
http://localhost:5155/odata/Registrations
Steps to reproduce
RegistrationsController
EDMModel