Vivekh
Vivekh

Reputation: 4259

Auto mapper Exception

I am trying to map my Models and i am getting error

        AtpWorldTourEntities obj = new AtpWorldTourEntities();
        Player _player;
        List<tblPlayer> _tblPlayer = obj.tblPlayers.ToList();
        //.FirstOrDefault();
        AutoMapper.Mapper.CreateMap<tblPlayer, Player>();
        _player = Mapper.Map<Player>(_tblPlayer);
        return View(_player);



Missing type map configuration or unsupported mapping.    
Mapping types:
List`1 -> Player
System.Collections.Generic.List`1[[MVCAPP.Models.tblPlayer, MVCAPP, Version=1.0.0.0,     
Culture=neutral, PublicKeyToken=null]] -> MVCAPP.Models.Player
Destination path:
Player
Source value:
System.Collections.Generic.List`1[MVCAPP.Models.tblPlayer]

Upvotes: 0

Views: 72

Answers (1)

Ross Bush
Ross Bush

Reputation: 15175

You can't map a Player to a List<Player>. Since you want to return a List<Player> you should map to a list instead:

Mapper.CreateMap<tblPlayer, Player>();
_player=Mapper.Map<List<tblPlayer>, List<Player>>(_tblPlayer);

Upvotes: 1

Related Questions