我在DTO和实体上有一个“ IsActive”字段。
public class Dto {
public int Id {get;set;}
public bool IsActive {get;set;}
}
public class Entity {
public int Id {get;set;}
public bool IsActive {get;set;}
}
而且我想在下面映射它
* Set value to true if Id == 0 * Ignore mapping if ID != 0
我该怎么办?
CreateMap<Dto, Entity>(MemberList.Source)
.ForMember(dto => dto.Active, options => options.Condition((dto, entity) => ??));
我将IsActive
保留在[C0]中,因为我需要将其传递给客户端。
最终这就是我得到的
Dto
.ForMember(entity => entity.Active, options => options.MapFrom((dto, entity) => dto.Id == 0 ? true : entity.Active))