Last active
November 25, 2018 10:38
-
-
Save lbargaoanu/b271bbd6b6d6845532f77a579dc83bdf to your computer and use it in GitHub Desktop.
ProjectToFlattening.cs
This file contains hidden or 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
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