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
My problem is that I want to be able to propagate metadata managed by EF Core (for example, MaxLength which can be looked up through IModel) all the way to the frontend, including DTO validation (I mean adding metadata to properties, just like DataAnnotations, but automatically), and up until the swagger schema. I haven't seen anyone ever do this in a project, but it feels like the only right way to go about this.
This should be in fact pretty easy to implement, given the mapping library offers a way to inspect the mapping metadata at a lower level. Basically, in the simplest case, you need to look at what property in the entity a given property of the dto maps to, and then query its metadata via dbContext.Model, then apply this metadata to the corresponding property of the DTO in some way (that's really less important).
I know there are cases when the properties are not mapped one-to-one, but the thing I described will cover 99% of cases. The things that don't map directly (two properties could be concatenated, or an int might end up as a string) can be validated after the mapping of the dto to the entity, and the errors reported via a backwards map (by looking up which properties the property of the entity was mapped from). This kind of advanced errors isn't expressible in either swagger or data annotations anyway.
So, my question is, does this library offer the sort of metadata mapping that could help one implement this? I mean looking up which property a given property maps to, and looking up which set of properties a property maps from if it's not mapped directly.
The text was updated successfully, but these errors were encountered:
AntonC9018
changed the title
Backwards-mapping metadata from target to source
Inspecting property maps gor validation and copying metadata
Jul 27, 2024
AntonC9018
changed the title
Inspecting property maps gor validation and copying metadata
Inspecting property maps for validation and copying metadata
Jul 27, 2024
AntonC9018
changed the title
Inspecting property maps for validation and copying metadata
Inspecting property maps for validation and copying of metadata
Jul 27, 2024
My problem is that I want to be able to propagate metadata managed by EF Core (for example,
MaxLength
which can be looked up throughIModel
) all the way to the frontend, including DTO validation (I mean adding metadata to properties, just like DataAnnotations, but automatically), and up until the swagger schema. I haven't seen anyone ever do this in a project, but it feels like the only right way to go about this.This should be in fact pretty easy to implement, given the mapping library offers a way to inspect the mapping metadata at a lower level. Basically, in the simplest case, you need to look at what property in the entity a given property of the dto maps to, and then query its metadata via
dbContext.Model
, then apply this metadata to the corresponding property of the DTO in some way (that's really less important).I know there are cases when the properties are not mapped one-to-one, but the thing I described will cover 99% of cases. The things that don't map directly (two properties could be concatenated, or an int might end up as a string) can be validated after the mapping of the dto to the entity, and the errors reported via a backwards map (by looking up which properties the property of the entity was mapped from). This kind of advanced errors isn't expressible in either swagger or data annotations anyway.
So, my question is, does this library offer the sort of metadata mapping that could help one implement this? I mean looking up which property a given property maps to, and looking up which set of properties a property maps from if it's not mapped directly.
The text was updated successfully, but these errors were encountered: