Skip to content

Instantly share code, notes, and snippets.

@stpriyanka
Last active March 30, 2017 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stpriyanka/8a4f641eb0a690cc4217a07577766ea4 to your computer and use it in GitHub Desktop.
Save stpriyanka/8a4f641eb0a690cc4217a07577766ea4 to your computer and use it in GitHub Desktop.
Map data from CompanyDTO to CompanyDM using Automapper
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