根据源属性的值是否需要忽略映射成员,这种情况是否可能?
例如,如果我们有:
public class Car
{
public int Id { get; set; }
public string Code { get; set; }
}
public class CarViewModel
{
public int Id { get; set; }
public string Code { get; set; }
}
我正在寻找类似于什么样的东西。Mapper.CreateMap<CarViewModel, Car>()
.ForMember(dest => dest.Code,
opt => opt.Ignore().If(source => source.Id == 0))
到目前为止,我唯一的解决方案是使用两个不同的视图模型,并为每个模型创建不同的映射。