.net 5 Map 使用注意事项
在Application 层可以做对象和Entity 的Map,
以下是ApplicationService中的定义
以下是接口IObjectMapper的定义
// 可以将entity map 成 dto
var result = ObjectMapper.Map<Entity, Dto>(Entity);
// 亦可将entity的list map 成 dto的list
var result = ObjectMapper.Map<List<Entity>, List<Dto>>(Entities);
// 也可将自定义的数据类型 map 成 dto
ObjectMapper.Map<Dictionary<Guid, Status>, StatusDto>(statusDic);
//注意此种情况需要在CreateMap时做 源数据和目标数据的转换
CreateMap<Dictionary<Guid, Status>, StatusDto>()
.ForMember(d => d.StatusDictionary, map => map.MapFrom(o => o));