Skip to content

Instantly share code, notes, and snippets.

@lbargaoanu
Last active November 25, 2018 10:38
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 lbargaoanu/b271bbd6b6d6845532f77a579dc83bdf to your computer and use it in GitHub Desktop.
Save lbargaoanu/b271bbd6b6d6845532f77a579dc83bdf to your computer and use it in GitHub Desktop.
ProjectToFlattening.cs
static void Main(string[] args)
{
Mapper.Initialize(cfg =>
{
cfg.AddProfile<MyMapperProfile>();
});
Mapper.AssertConfigurationIsValid();
new[]{new OrderDTO{ customer = new customer { ID = 1, name = "john" }}}.AsQueryable().ProjectTo<Order>().Dump();
}
public class Order
{
public int ID { get; set; }
public int customer_id { get; set; }
public string customer_name { get; set; }
}
public class OrderDTO
{
public int ID { get; set; }
public customer customer { get; set; }
}
public class customer
{
public int ID { get; set; }
public string name { get; set; }
}
public class MyMapperProfile : Profile
{
public MyMapperProfile()
{
this.SourceMemberNamingConvention = new LowerUnderscoreNamingConvention();
this.DestinationMemberNamingConvention = new LowerUnderscoreNamingConvention();
CreateMap<OrderDTO, Order>()
.ForMember(m => m.ID, src => src.Ignore())
.ReverseMap();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment