Last active
March 30, 2017 14:33
-
-
Save stpriyanka/8a4f641eb0a690cc4217a07577766ea4 to your computer and use it in GitHub Desktop.
Map data from CompanyDTO to CompanyDM using Automapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BusinessLogic | |
{ | |
public CompanyDTO CompanyDto { get; set; } | |
public CompanyDM CompanyDm { get; set; } | |
public BusinessLogic(CompanyDTO dto, CompanyDM dm) | |
{ | |
CompanyDto = dto; | |
CompanyDm = dm; | |
} | |
public CompanyDM MapData() | |
{ | |
// Configure and declare mapping from sourceFile to DestinationFile | |
var config = new MapperConfiguration(cfg => | |
{ | |
cfg.CreateMap<CompanyDTO, CompanyDM>() | |
//UseDestinationValue tells AutoMapper not to create a new object for some member, | |
//but to use the existing property of the destination object. | |
.ForMember(dst => dst.URL, opt => opt.MapFrom(src => src.CompanyWebsite)); | |
}); | |
var mapper = config.CreateMapper(); | |
CompanyDM dataContainer = mapper.Map<CompanyDM>(CompanyDto); | |
return dataContainer; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment