ใช้ Automapper สำหรับการจับคู่โมเดลโดเมนขนาดใหญ่กับออบเจกต์ฐานข้อมูล

public abstract class SyncMappingWrapper<TFrom> where TFrom : class
{
    protected SyncMappingWrapper(TFrom model)
    {
        Model = model;
    }

    public TFrom Model { get; private set; }
}

public class Update<TFrom> : SyncMappingWrapper<TFrom> where TFrom : class
{
    public Update(TFrom model)
        : base(model)
    {
    }
}

public class Insert<TFrom> : SyncMappingWrapper<TFrom> where TFrom : class
{
    public Insert(TFrom model)
        : base(model)
    {
    }
}
CreateMap<Update<OracleModel>, LiveModel>()
            .ForMember(des => des.ApprovedBy, opt => opt.Ignore())
            .ForMember(des => des.ApprovedDate, opt => opt.Ignore())
            ...
            .ForMember(des => des.UNSPSC, opt => opt.Ignore())
            .ForMember(des => des.BaseUnit, opt => opt.MapFrom(src => src.Model.UOM.BaseUOM.PerSalesUnit))
            .ForMember(des => des.BaseUOM, opt => opt.MapFrom(src => src.Model.UOM.BaseUOM.UnitOfMeasure.Code))
            .ForMember(des => des.SalesUnit, opt => opt.MapFrom(src => src.Model.UOM.SalesUOM.PerSalesUnit))
            .ForMember(des => des.SalesUOM, opt => opt.MapFrom(src => src.Model.UOM.SalesUOM.UnitOfMeasure.Code))
            .ForMember(des => des.OrderUnit, opt => opt.MapFrom(src => src.Model.UOM.OrderUOM.PerSalesUnit))
            .ForMember(des => des.OrderUOM, opt => opt.MapFrom(src => src.Model.UOM.OrderUOM.UnitOfMeasure.Code))
            .ForMember(des => des.SalesPrice, opt => opt.MapFrom(src => src.Model.Price.Value))
            .ForMember(des => des.Alternate, opt => opt.Ignore())
            .ForMember(des => des.ManufacturerID, opt => opt.Ignore())
            .ForMember(des => des.ProductCode, opt => opt.MapFrom(src => src.Model.ProductCode))
            .ForMember(des => des.ProductName, opt => opt.MapFrom(src => src.Model.ProductName))
            .ForMember(des => des.ProductHTML, opt => opt.Ignore())
            .ForMember(des => des.Version, opt => opt.Ignore())
            ...
            .ForMember(des => des.UnitsOfMeasure2, opt => opt.Ignore())
            .ForMember(des => des.Manufacturer, opt => opt.Ignore());