在我的应用程序中,我必须使用映射。
我的Source对象的结构是
public class SourceContract
{
public string ContractNo {get; set;}
public string ContractDescription {get; set;}
List<SourceSalary> SourceSalaries {get;set;}
}
来源工资是
public class SourceSalary
{
public string SalaryNo {get; set;}
public int SalaryFixed {get; set;}
}
目标对象的结构是
public class DestinationContract
{
public string DestinationContractNo {get; set;}
public string DestinationDescription {get; set;}
List<DestinationSalary> DestinationSalaries {get;set;}
}
目的地薪水是
public class DestinationSalary
{
public string DestinationSalaryNo {get; set;}
pubbic int DestinationSalaryFixed {get; set;}
}
现在我正在使用两个映射器
AutoMapper.Mapper.CreateMap<
SourceContract, DestinationContract>()
.ForMember(dest => dest.DestinationContractNo, opt => opt.MapFrom(src => src.ContractNo))
.ForMember(dest => DestinationDescription, opt => opt.MapFrom(src => src.ContractDescription))
并且
AutoMapper.Mapper.CreateMap<
SourceSalary, DestinationSalary>()
.ForMember(dest => dest.DestinationSalaryNo, opt => opt.MapFrom(src => src.SalaryNo))
.ForMember(dest => DestinationSalaryFixed, opt => opt.MapFrom(src => src.SalaryFixed))
我只想使用一个Mapper
我无法使用嵌套映射,因为SourceContract包含List而DestinationContract也包含List
有没有办法在One Mapper中映射?像嵌套映射
P.S-我不能改变nethier目的地的名称或结构,也不能改变Source。