一.AutoMapper使用中的问题
1. 指定值只会执行一次
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()))
.ForMember(d => d.CreateTime, op => op.UseValue(DateTime.UtcNow))
.ForMember(d => d.UpdateTime, op => op.UseValue(DateTime.UtcNow));
CreateMap<RequestWithUserBase, MomanEntity>()
.IncludeBase<RequestBase, MomanEntity>();
}
}
2. 继承类如何减少Map问题解决
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));
CreateMap<RequestWithUserBase, MomanEntity>()
.IncludeBase<RequestBase, MomanEntity>();
}
}