❔ Automapper map Id to Entity
I receive the following DTO (request)
BookDTO{
int Id,
int AuthorId
}
I want the mapper to map AuthorId to the Author entity and put in into the Book.Author.
How do I do this? Should I inject the dbcontext into my profiles?
Or can I simply map Dto AuthorId to Entity AuthorId and it will be fine and navigation will be filled once context is saved?
What is the best way?
11 Replies
automapper has nothing to do with that, you'd just set the author id on the book entity
and not even use automapper
But If I dont want to do this manually?
I mean yes I get that this is the way it can be done
without automapper
you're saving one line of code
you do realise this
yes, but there will be more properties
i once tried to have the full mapping in my services
ok. so should i map plain (strings, etc) properties with automapper and the complex ones (id to entity) in my services?
is it how its done usually?
that's opinion; i dont recommend automapper at all, ever
because of poor perf?
and reflection being unintuitive
because it's a magic box and you have no idea what's going on, property name changes requires as much as configuration as you just mapping properties yourself and people end up testing if automapper maps stuff
hmm yeah
thank you
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.