Skip to content

Instantly share code, notes, and snippets.

@brunomartinspro
Created July 10, 2018 11:30
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 brunomartinspro/4889edf69d58dea58101302c7c0f5eb7 to your computer and use it in GitHub Desktop.
Save brunomartinspro/4889edf69d58dea58101302c7c0f5eb7 to your computer and use it in GitHub Desktop.
Use AutoMapper to map properties
using AutoMapper;
using BrunoMartinsPro.Data;
namespace BrunoMartinsPro.Config
{
public class AutoMapperConfig
{
/// <summary>
/// Initialize and configure AutoMapper Mappings
/// </summary>
public static void Initialize()
{
Mapper.Initialize(config =>
{
config.CreateMap<PropertyModel, PropertyDto>()
.ForMember(destination => destination.UId,
origin => origin.MapFrom(property => property.Id))
.ForMember(destination => destination.Date,
origin => origin.MapFrom(property => property.Date.ToString("yyyy-MM-dd hh:MM:ss")));
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment