Automapper将列表与列表映射到列表
问题描述:
我遇到了Automapper问题。我的映射表调用看起来像:Automapper将列表与列表映射到列表
var dataContracts = MapperManager.Mapper.Map<List<Employee>, List<EmployeeDTO>>(entities.ToList());
实体是IQueryable<Employee>
在我的映射器的辅助类,我有:
public class MapperManager
{
public static MapperConfiguration MapperConfiguration { get; set; }
private static IMapper _mapper { get; set; }
public static IMapper Mapper
{
get
{
if (_mapper == null) {
_mapper = MapperConfiguration.CreateMapper();
}
return _mapper;
}
}
public static void RegisterMappinngs()
{
MapperConfiguration = new MapperConfiguration(cfg =>
{
...
cfg.CreateMap<Employee, EmployeeDTO>().MaxDepth(5);
...
}
}
}
RegisterMappings上AppStartup调用一次在Global.asax中 和我后地图操作中的例外情况:
var dataContracts = MapperManager.Mapper.Map<List<Employee>, List<EmployeeDTO>>(entities.ToList());
错误映射类型。
映射类型: List`1 - > List`1 System.Collections.Generic.List`1 [[NAMESPACE.Employee,ASSEMBLY, 版本= 1.0.0.0,文化=中性公钥=空]] - > System.Collections.Generic.List`1 [NAMESPACE2.EmployeeDTO,ASSEMBLY2, 版本= 1.0.0.0,文化=中立,公钥=空]
任何人都可以提供任何想法我什么做错了?
问候
答
好吧,这就是答案:
MapperConfiguration.AssertConfigurationIsValid()
当我打电话说,我AMConfigurationException与unmaped财产,内心深处的另一名员工财产。
谢谢您的建议
您是否可以映射单个Employee - > EmployeeDTO?您的配置可能不完整。如果你调用MapperConfiguration.AssertConfigurationIsValid(),会发生什么? –