Error Mapping types. Mapping types: Icollection`1 -> List`1

Asked

Viewed 830 times

0

I’m having a problem converting a List for ViewModel, using the ToListViewModel.

Faturacontroller.Cs

FaturaViewModel faturaViewModel = new FaturaViewModel();

faturaViewModel.mensagens = new List<MensagemViewModel>();

faturaViewModel.mensagens = this.ToListViewModel<Mensagem, MensagemViewModel>(_MensagemApplicationService.GetAllAsNoTracking().ToList());

return View(faturaViewModel);

The Model and the ViewModel has the same fields.

Faturaviewmodel.Cs

public List<MensagemViewModel> mensagens { get; set; }

Exception

System.Exception: 'Error mapping types.

Mapping types:
ICollection`1 -> List`1
System.Collections.Generic.ICollection`1

1 answer

0


I managed to create a new Mapper, both from Domanin to Viewmodel and Viewmodel to Domain to property public List<MensagemViewModel> mensagens { get; set; }:

Domaintoviewmodel

this.CreateMap<Mensagem, MensagemViewModel>();

Viewmodeltodomain

this.CreateMap<MensagemViewModel, Mensagem>();

Note: I also had to do this for all ViewModels.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.