Automapper and List Problems

Asked

Viewed 141 times

1

Guys, I have the following code:

            List<NFE_CABECALHOEntity> lista = new List<NFE_CABECALHOEntity>();

                Mapper.Initialize(cfg => { cfg.CreateMap<NFE_CABECALHO, NFE_CABECALHOEntity>(); });

            lista = Mapper.Map<List<NFE_CABECALHO> ,List<NFE_CABECALHOEntity>>(listaData);

but I’m not getting the objects from the list?

It shows the following error:

Mapping types: List1 -> List1 System.Collections.Generic.List1[[Data.Entity.NFE_CABECALHO, Data, Version=1.5.0.0, Culture=neutral, PublicKeyToken=null]] -> System.Collections.Generic.List1[[Entity.Model.Nfe_cabecalhoentity, Entity, Version=1.8.2.0, Culture=neutral, Publickeytoken=null]]

  • Is generating error or the object comes empty?

  • Sorry, this includes the error you are showing.

1 answer

1


Try it this way:

Mapper.Initialize(cfg => { cfg.CreateMap<NFE_CABECALHO, NFE_CABECALHOEntity>(); });

var lista = Mapper.Map<List<NFE_CABECALHOEntity>>(listaData);

Mapper may be getting lost because you are using two type arguments with only one parameter, then you may be calling the wrong method.

  • It worked thanks :D

Browser other questions tagged

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