0

In my application i have to use mapping.

Structure of my Source object is

 public class SourceContract  
    {  
     public string ContractNo {get; set;}  
     public string ContractDescription {get; set;}  
    List<SourceSalary> SourceSalaries {get;set;}  
    }

Source salary is

  public class SourceSalary  
    {  
     public string SalaryNo {get; set;}  
     public int SalaryFixed {get; set;}  

    }

Structure of Destination Object is

 public class DestinationContract  
    {  
     public string DestinationContractNo {get; set;}  
     public string DestinationDescription {get; set;}  
    List<DestinationSalary> DestinationSalaries {get;set;}  
    }

Destination Salary is

public class DestinationSalary  
{  
 public string DestinationSalaryNo {get; set;}  
 pubbic int DestinationSalaryFixed {get; set;}  

}

Now I am using two mappers

 AutoMapper.Mapper.CreateMap<
SourceContract, DestinationContract>()
                .ForMember(dest => dest.DestinationContractNo, opt => opt.MapFrom(src => src.ContractNo))  
                .ForMember(dest => DestinationDescription, opt => opt.MapFrom(src => src.ContractDescription))

And

AutoMapper.Mapper.CreateMap<
        SourceSalary, DestinationSalary>()
                        .ForMember(dest => dest.DestinationSalaryNo, opt => opt.MapFrom(src => src.SalaryNo))  
                        .ForMember(dest => DestinationSalaryFixed, opt => opt.MapFrom(src => src.SalaryFixed))

I want to use only one Mapper

I am not able to use nested mapping because SourceContract contains List and DestinationContract also contains List

Is there any way that I can map in One Mapper?? something like nested mapping

P.S- I cannot change the names or structure of nethier destination nor Source.

user2739679
  • 827
  • 4
  • 14
  • 24
  • Why do you want to use just one mapping? The way you have it now is clear and unambiguous. Should you want to reuse SourceSalary and DestinationSalary in the future within a different class then the mapping is already there for you. – Gruff Bunny Oct 08 '13 at 15:53
  • I want one mapping because everytime i map SourceContract to DestinationContract i have to map SourceSalary to DestinationSalary. – user2739679 Oct 09 '13 at 06:07
  • 1
    You only have to create the mapping once when your app starts. Performing the mapping should be a one liner. – Gruff Bunny Oct 09 '13 at 07:11

0 Answers0