I have some services with methods that return DTO’s back to my controllers. Like
_user userObject = _userService.GetUser();
IUser is injected making _user available.
This all works but I am having to write all of the mappings by hand from the entity to the DTO that gets returned and it is a big pain in the butt.
So like:
var user = _repository.GetById(userId);
_userDto.userName = user.UserName;
so on and so forth with the rest of the props for the DTO.
Is this something that Automapper can help me out with? I have read that it is not good practice to use automapper for this purpose but I don’t see why not and question the source at this point.
Each one of my Nhibernate entities may have several entities depending on what I fetch etc.. Like profile, userType. This is getting insane..
Yes, you can use AutoMapper to map between entities and DTOs.