Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Source
- {
- public Tbl_Child Child { get; set; }
- public string SourceName { get; set; }
- }
- public class Tbl_Child
- {
- public int ID_Child { get; set; }
- public string ChildName { get; set; }
- }
- public class Destination
- {
- public int FK_Child { get; set; }
- public string ChildName { get; set; }
- public string SourceName { get; set; }
- }
- static void Main(string[] args)
- {
- var src = new Source()
- {
- Child = new Tbl_Child()
- {
- ChildName = "ch",
- ID_Child = 1
- },
- SourceName = "src"
- };
- AutoMapper.Mapper.CreateMap<Source, Destination>();
- var dest = AutoMapper.Mapper.Map<Source, Destination>(src);
- Console.ReadKey();
- }
- Mapper.CreateMap<Source, Destination>()
- .ForMember(d => d.FK_Child, o => o.MapFrom(s => s.Child.ID_Child));
- Mapper.CreateMap<Source, Destination>()
- .ForMember(d => d.FK_Child, o => o.MapFrom(s => s.Child.ID_Child))
- .ForMember(d => d.ChildName, o => o.MapFrom(s => s.Child.ChildName));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement