Mapping to inherited interface not working
See original GitHub issueI have the following mapping config defined
config.NewConfig<OrderStatusSaveDto, IOrderStatus>()
.ConstructUsing(src => null);
(NB ConstructUsing(src => null) is because I don’t want the mapper to be in control of constructing the interface, it will always be passed an instance)
And then in a controller I receive an OrderStatusSaveDto from the post body (which is populated). I then retrieve an IOrderStatus entity from a service and call the following to map the properties over
orderStatus.Adapt(entity);
After this call however, the entity hasn’t been populated at all.
Should Mapster be able to map to an interface like this?
Issue Analytics
- State:
- Created 4 years ago
- Comments:5
Top Results From Across the Web
c# - Inherited Interface property not found by Model Binding
Take a look at AutoMapper for what classes your views should be mapping to. The quick summary: create view-specific models (i.e. View Models) ......
Read more >C# | Inheritance in interfaces
When a class implements the inherited interface then it must provide the implementation of all the members that are defined within the interface...
Read more >Hibernate Inheritance Mapping
A practical guide to understanding different inheritance mapping strategies with JPA / Hibernate.
Read more >Interfaces - C# language specification
An interface may inherit from multiple base interfaces, and a class or struct may implement multiple interfaces. Interfaces can contain methods, ...
Read more >Mapping GDMO Templates to IDL Interfaces
In CORBA IDL, an attribute or operation cannot be inherited from more than one interface, whereas in GDMO such multiple declaration is allowed....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is might actually a bug. Mapster use
type.GetProperties(...)to retrieve all properties. This method for class, it will also return inherited properties. However for interface, it will only return declare properties.Fixing this issue might has side effect, I will see how to fix this.
Hi @chaowlert, My apologies for my late response. It has to do with the multiple projects i’m working on currently. Today i took your unittest to check if this worked. I had to add an inherited interface without extra properties and tried to adapt it to an model. Same error occurs here. It is not covered by the current tests because you do dto > interface. I’m trying to map interface > dto.
Maybe that’s why it does not work? Btw it happens on compilation of the typeadapter.
The exception thrown is: