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

How to map ExtraProperties of an entity to a type-safe DTO? #3128

Closed
hikalkan opened this issue Mar 15, 2020 · 4 comments · Fixed by #7666
Closed

How to map ExtraProperties of an entity to a type-safe DTO? #3128

hikalkan opened this issue Mar 15, 2020 · 4 comments · Fixed by #7666

Comments

@hikalkan
Copy link
Member

ExtraProperties of an entity is a dictionary that contains some additional properties related to the entity.

If you map such an entity to a DTO (or vice verse), the values in the extra properties will not be mapped as you can expect. You can manually define AutoMapper mapping configuration.

Since this is pretty standard, we can define some extension methods & conventions to make this easier.

@iyilm4z
Copy link
Contributor

iyilm4z commented Jan 18, 2021

I think this feature is already implemented here?

@hikalkan
Copy link
Member Author

No, it doesn't. It maps Obj1.ExtraProperties to Obj2.ExtraProperties (copy the items inside the dictionary).
This issue is about copying an item in the dictionary to a regular property of another object. Obj1.ExtraProperties["Name"] to Obj2.Name.

@iyilm4z
Copy link
Contributor

iyilm4z commented Jan 28, 2021

As you know we use ExtensibleObjectMapper for mapping SrcObj.ExtraProperties to DestObj.ExtraProperties. This class contains methods working with two objects implement IHasExtraProperties interface.

Below possible steps to help us having this feature.

1-Make implementing IHasExtraProperties optional for destination objects in ExtensibleObjectMapper or create a new class specially for this feature(we always should apply required extensible object logic for source)
2- Use Apb's json serializer for mapping ExtraProperties of source to destination's properties like here.(this is just a logic, sure we can modify it)

What do you think about this possible solution?

@hikalkan
Copy link
Member Author

hikalkan commented Feb 7, 2021

Hi,

1- I thought we can just an option to MapExtraProperties definition here: https://docs.abp.io/en/abp/latest/Object-To-Object-Mapping#mapping-the-object-extensions (like bool mapToRegularProperties = false).
2 - I wouldn't use the JSON serialization for such a simple think that can be easily done via reflection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants