✅ AutoMapper record to class problems
I need to create map from
to:
I quickly made it:
So I want keep Id, AuthorId, Text and SendDate be mapped
But it throws exception:
AutoMapper.AutoMapperMappingException
Message=Error mapping types.
Source=AutoMapper
Inner Exception 1:
AutoMapperMappingException: Missing type map configuration or unsupported mapping.
So what I did wrong?
Surprising, this maps fine:
6 Replies
Are you mapping from a DTO to a database entity?
Yes
Thats generally not a great idea - since your nav props etc will all be empty.
Hm, so what is the best practice?
you'll need to add ignores to all unmapped properties for the destination, and the
Likes
property is causing issues since it has different types
well the only possible scenario where mapping from a dto to an entity would make any sense would be for creating a new from scratch
but at that point you dont have any IDs usually
better to just have a CreateXRequest
and create the entity based on the info in that, manually.
Mapping is mostly done from entity->dto for representation purposes, or even better, with a .ProjectTo
Queryable extensionHah, the problem is I need to pass huge json file which structure wasn't designed to be good for database
Any way thx, Ill ignore all properties that can be mapped - it helps a bit 😄