C
C#2y ago
joy

automapper in net framework

hi all, i tried to implement automapper using net framework 4.7.2, i tried in net core im able to convert from NoteItem to Note (same data retrieved from database), but when i implement this in net framework the noteResult give me 0 result, even tho there's no exception or error thrown, can anyone help advise what could be wrong?
var config = new MapperConfiguration(cfg => {
cfg.CreateMap<List<NoteItem>, List<Note>>();
});

IMapper mapper = config.CreateMapper();
var noteResult = mapper.Map<List<NoteItem>, List<Note>>(result); //result have list of NoteItem retrieved from a database
var config = new MapperConfiguration(cfg => {
cfg.CreateMap<List<NoteItem>, List<Note>>();
});

IMapper mapper = config.CreateMapper();
var noteResult = mapper.Map<List<NoteItem>, List<Note>>(result); //result have list of NoteItem retrieved from a database
5 Replies
Becquerel
Becquerel2y ago
i don't think it's standard to set up mappings between List<T> and List<X> you'd do the mapping between T and X directly then if you want to map a list, you just do it inside a .Select()
joy
joy2y ago
omg.. it works after i changed the mapping to T and X instead of List<T> to List<X>
var config = new MapperConfiguration(cfg => {
cfg.CreateMap<NoteItem, Note>();
});

IMapper mapper = config.CreateMapper();
var noteResult = mapper.Map<List<Note>>(result);
var config = new MapperConfiguration(cfg => {
cfg.CreateMap<NoteItem, Note>();
});

IMapper mapper = config.CreateMapper();
var noteResult = mapper.Map<List<Note>>(result);
joy
joy2y ago
previously i was following the mapping like this solution..
joy
joy2y ago
thank you!!
Becquerel
Becquerel2y ago
no prob note that here they already have a mapping between Person and PersonView and then they can perform the mapping between lists of those types they don't set up the mapping between List<Person> and List<PersonView> that's why they say you don't need to repeat for Lists