Advertisement
Guest User

Untitled

a guest
Apr 20th, 2014
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. public class Source
  2. {
  3. public Tbl_Child Child { get; set; }
  4.  
  5. public string SourceName { get; set; }
  6. }
  7.  
  8. public class Tbl_Child
  9. {
  10. public int ID_Child { get; set; }
  11. public string ChildName { get; set; }
  12. }
  13.  
  14. public class Destination
  15. {
  16. public int FK_Child { get; set; }
  17. public string ChildName { get; set; }
  18. public string SourceName { get; set; }
  19. }
  20.  
  21. static void Main(string[] args)
  22. {
  23. var src = new Source()
  24. {
  25. Child = new Tbl_Child()
  26. {
  27. ChildName = "ch",
  28. ID_Child = 1
  29. },
  30. SourceName = "src"
  31. };
  32.  
  33. AutoMapper.Mapper.CreateMap<Source, Destination>();
  34. var dest = AutoMapper.Mapper.Map<Source, Destination>(src);
  35.  
  36. Console.ReadKey();
  37. }
  38.  
  39. Mapper.CreateMap<Source, Destination>()
  40. .ForMember(d => d.FK_Child, o => o.MapFrom(s => s.Child.ID_Child));
  41.  
  42. Mapper.CreateMap<Source, Destination>()
  43. .ForMember(d => d.FK_Child, o => o.MapFrom(s => s.Child.ID_Child))
  44. .ForMember(d => d.ChildName, o => o.MapFrom(s => s.Child.ChildName));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement