IncludeMembers Inheritance #3812
NismanSolutions
started this conversation in
NA
Replies: 1 comment
-
Try the MyGet build. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to reuse the base map that has both ForMember explicit mapping and IncludeMembers for a nested object in the derived classes using IncludeBase. This always results in an error: 'Property [baseProperty] is not defined for type [nestedType]'.
Here is the code:
https://gist.github.com/NismanSolutions/e7a73fe1c295d2c80fa115c85295aabd
class GroupUser
{
int userId;
ApplicationUser User;
}
class ApplicationUser
{
}
class UserDto
{
int id;
}
class User2Dto : UserDto
{
}
CreateMap<GroupUser, UserDto>()
.IncludeMembers(src => src.User)
.ForMember(dest => dest.id, memb => memb.MapFrom(src => src.userId)); // This causes the error in the derived mapping
CreateMap<GroupUser, User2Dto>()
.IncludeBase<GroupUser, UserDto>();
Error: "Property 'userId' is not defined for type 'ApplicationUser'"
Why is it trying to use userId on nested type ApplicationUser? I'd expect that this should maintain the relation of the userId mapping with the original source type: GroupUser where the userId is defined. Am I missing something or this is a bug?
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions