自动映射器异常

时间:2014-07-18 14:25:52

标签: entity-framework automapper

我正在尝试映射我的模型,但我收到错误

        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]

1 个答案:

答案 0 :(得分:1)

您无法将Player映射到List<Player>。由于您想要返回List<Player>,您应该映射到列表:

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