首先需要在NuGet中引用AutoMapper的类库
声明:
若class类型参数一致则:
Mapper.Initialize(x => x.CreateMap<原始Class, 须赋值Class>()));
若扩展参数:
Mapper.Initialize(x => x.CreateMap<business_Labi_CourseEnrollOrder, business_Labi_CourseEnrollOrderDto>().ForMember(y=>y.OrderDetails,dto=>dto.MapFrom(s=>s.OrderDetails.Select(t=>new business_Labi_CourseEnrollOrderDto.OrderDetail
{
ProductVersionID = t.ProductVersionID,
Qty = t.Qty,
SalePrice = t.SalePrice,
}))));
调用:
var info = Mapper.Map<business_Labi_CourseEnrollOrder, business_Labi_CourseEnrollOrderDto>(item);