public class MomanBaseProfile : Profile { public MomanBaseProfile() { CreateMap<RequestBase, MomanEntity>() .ForMember(d => d.ID, op => op.Ignore()) .ForMember(d => d.UID, op => op.UseValue(Guid.NewGuid()))//使用Mapper過程當中始終不變 .ForMember(d => d.CreateTime, op => op.UseValue(DateTime.UtcNow)) .ForMember(d => d.UpdateTime, op => op.UseValue(DateTime.UtcNow)); CreateMap<RequestWithUserBase, MomanEntity>() .IncludeBase<RequestBase, MomanEntity>(); } }
public class MomanBaseProfile : Profile { public MomanBaseProfile() { CreateMap<RequestBase, MomanEntity>() .ForMember(d => d.ID, op => op.Ignore()) .ForMember(d => d.UID, x => x.MapFrom(ax => Guid.NewGuid())) .ForMember(d => d.CreateTime, x => x.MapFrom(ax => DateTime.UtcNow)) .ForMember(d => d.UpdateTime, x => x.MapFrom(ax => DateTime.UtcNow)); //繼承類兩種方式,一種使用IncludeBase(從父類映射繼承)以下,另外一中使用Include(從子類映射繼承) CreateMap<RequestWithUserBase, MomanEntity>() .IncludeBase<RequestBase, MomanEntity>(); } }