假设我有这些映射:
var mapping1 = Mapper.CreateMap<Order, BaseDto>()
.ForMember(o => o.Referrer, m => m.Ignore());
var mapping2 = Mapper.CreateMap<Order, DetailDto>()
.ForMember(o => o.Price, m => m.Ignore());
var mapping3 = Mapper.CreateMap<Order, UpdateDto>()
.ForMember(o => o.Temp, m => m.Ignore());
Dtos的继承:
DetailDto : BaseDto
UpdateDto : BaseDto
有什么方法可以将第一个映射合并/组合到 mapping2 和 mapping3 中?
像这样的东西:
var mapping1 = Mapper.CreateMap<Order, BaseDto>()
.ForMember(o => o.Referrer, m => m.Ignore());
var mapping2 = Mapper.CreateMap<Order, DetailDto>()
.Import(mapping1);
.ForMember(o => o.Price, m => m.Ignore());
var mapping3 = Mapper.CreateMap<Order, UpdateDto>()
.Import(mapping1);
.ForMember(o => o.Temp, m => m.Ignore());
该.Include
功能似乎没有做我想要的,因为以下不起作用:
var mapping1 = Mapper.CreateMap<Order, BaseDto>()
.Include<Order, DetailDto>()
.Include<Order, UpdateDto>()
.ForMember(o => o.Referrer, m => m.Ignore());
var mapping2 = Mapper.CreateMap<Order, DetailDto>()
.ForMember(o => o.Price, m => m.Ignore());
var mapping3 = Mapper.CreateMap<Order, UpdateDto>()
.ForMember(o => o.Temp, m => m.Ignore());
更新:编辑问题更具体