Reputation: 105
What's the mistake in the following code, when I try to copy on List to an other?
The count of list
is always 0.
using (WeldingEntities db = new WeldingEntities())
{
var query = db.Users.Select(x => x).ToList();
var config = new MapperConfiguration(cfg => cfg.CreateMap<List<User>, List<SimpleUser>>());
var mapper = config.CreateMapper();
var list = mapper.Map<List<SimpleUser>>(query);
return list;
}
Upvotes: 0
Views: 360
Reputation: 4471
You don't specify the collection type in your map definition. You just need to specify the individual type and automapper can figure out collection mapping on its own.
var config = new MapperConfiguration(cfg => cfg.CreateMap<User, SimpleUser>());
See docs for more info on the collection types that are supported.
Upvotes: 2