-
Notifications
You must be signed in to change notification settings - Fork 334
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
Instance creation of derived class from an abstract class #52
Comments
Hi jigneshkvp,
|
THanks for the heads-up, the abstract type should be ok. I'll add a test case to test this in a bit. |
Ahh...I see the issue now. Because your ProductDto has a list of VehicleDto, it's trying to map to the VehicleDto type (meaning it will try to new up this type). It can't assume you want to map to CarDto just because that is one mapping that is defined. You have to know the destination type you are mapping to. Problem is that if you have several vehicle types, you'll need some kind of logic in the mapping to differentiate the type to map to. |
This is interesting issue. I will check how EF can return information from abstract class. For now, could you remove from |
Hi, I managed to do something like this as suggested by BuzzDee3000 (Thanks!):
In AutoMapper 4.2.1, inheritance is handled as follows and it automatically takes care of instantiating concrete classes from abstract classes:
It would have been really great if we could have something similar in Mapster. Also, what I do use in AutoMapper is the "Profile" class, which provides named configuration for maps.
So I can register/add all profiles during Application_Start and then my Mapping is done once for the session. I then resolve the mapping using the "MappingEngine" class which I pass as a dependency wherever required. Could you suggest me something similar in Mapster? Thanks for your quick response! 👍 |
Hi @jigneshkvp , it make sense to see if we have a mapping that qualifies as a "default/defined" mapping for that destination type already registered. I'll leave this issue open and take a look. |
Hi, I added |
Hello @eswann , @chaowlert,
I am facing a particular issue where I have a derived class inheriting from a base abstract class and Mapster give me an error "Instances of abstract classes cannot be created". Consider the example below:
I have a TPT database model, where my Car inherits from Vehicle, my EF model reflects it.
My Dto objects are:
My Mapping is:
The actual call
What wrong am I doing? Is there any mapping registration issue? or Mapster is unable to handle abstract class? Please let me know.
Thanks!
The text was updated successfully, but these errors were encountered: