Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inspecting property maps for validation and copying of metadata #721

Open
AntonC9018 opened this issue Jul 27, 2024 · 0 comments
Open

Inspecting property maps for validation and copying of metadata #721

AntonC9018 opened this issue Jul 27, 2024 · 0 comments

Comments

@AntonC9018
Copy link

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.

@AntonC9018 AntonC9018 changed the title Backwards-mapping metadata from target to source Inspecting property maps gor validation and copying metadata Jul 27, 2024
@AntonC9018 AntonC9018 changed the title Inspecting property maps gor validation and copying metadata Inspecting property maps for validation and copying metadata Jul 27, 2024
@AntonC9018 AntonC9018 changed the title Inspecting property maps for validation and copying metadata Inspecting property maps for validation and copying of metadata Jul 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant