{"action":"created","issue":{"url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/1107","repository_url":"https://api.github.com/repos/AutoMapper/AutoMapper","labels_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/1107/labels{/name}","comments_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/1107/comments","events_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/1107/events","html_url":"https://github.com/AutoMapper/AutoMapper/issues/1107","id":133443767,"number":1107,"title":"Nesting of complex types acorss various destination objects","user":{"login":"dixitsuneel","id":12703917,"avatar_url":"https://avatars.githubusercontent.com/u/12703917?v=3","gravatar_id":"","url":"https://api.github.com/users/dixitsuneel","html_url":"https://github.com/dixitsuneel","followers_url":"https://api.github.com/users/dixitsuneel/followers","following_url":"https://api.github.com/users/dixitsuneel/following{/other_user}","gists_url":"https://api.github.com/users/dixitsuneel/gists{/gist_id}","starred_url":"https://api.github.com/users/dixitsuneel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dixitsuneel/subscriptions","organizations_url":"https://api.github.com/users/dixitsuneel/orgs","repos_url":"https://api.github.com/users/dixitsuneel/repos","events_url":"https://api.github.com/users/dixitsuneel/events{/privacy}","received_events_url":"https://api.github.com/users/dixitsuneel/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-02-13T15:56:44Z","updated_at":"2016-02-13T17:09:18Z","closed_at":null,"body":"I have the following code structure for a back end entity\r\n`public class Employee{\r\npublic Address Address{get;set;}\r\n}`\r\n\r\n`public class Address{\r\npublic string Line1{get;set;}\r\npublic string Line2{get;set;}\r\npublic string City{get;set;}\r\npublic string Zip{get;set;}\r\n}`\r\n\r\nMy DTO objects have the following code structure\r\n\r\n`class Provider{\r\npublic string AddressLine1{get;set;}\r\npublic string AddressLine2{get;set;}\r\npublic string City{get;set;}\r\npublic string Zip{get;set;}\r\n}`\r\n\r\n`class Admin{\r\npublic string AddressLine1{get;set;}\r\npublic string AddressLine2{get;set;}\r\npublic string City{get;set;}\r\npublic string Zip{get;set;}\r\n}`\r\n\r\nNow, Here's my auto mapper mapping\r\n\r\n`Mapper.CreateMap<Employee,Provider>()\r\n.ForMember(t=>t.City,opt=>opt.MapFrom(src=>src.Address.City))\r\n.ForMember(t=>t.Zip,opt=>opt.MapFrom(src=>src.Address.Zip)\r\n\r\nMapper.CreateMap<Employee,Admin>()\r\n.ForMember(t=>t.City,opt=>opt.MapFrom(src=>src.Address.City))\r\n.ForMember(t=>t.Zip,opt=>opt.MapFrom(src=>src.Address.Zip)\r\n`\r\n\r\nI have various scenarios like these where a nested object needs to be flattended and majority of time the same complex type needs to be mapped to same properties in various destination objects.\r\n\r\nIs there a better way writing this map? Currently I have to write this map for every new person type I have in the system. \r\n\r\n"},"comment":{"url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/comments/183704373","html_url":"https://github.com/AutoMapper/AutoMapper/issues/1107#issuecomment-183704373","issue_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/1107","id":183704373,"user":{"login":"lbargaoanu","id":4517428,"avatar_url":"https://avatars.githubusercontent.com/u/4517428?v=3","gravatar_id":"","url":"https://api.github.com/users/lbargaoanu","html_url":"https://github.com/lbargaoanu","followers_url":"https://api.github.com/users/lbargaoanu/followers","following_url":"https://api.github.com/users/lbargaoanu/following{/other_user}","gists_url":"https://api.github.com/users/lbargaoanu/gists{/gist_id}","starred_url":"https://api.github.com/users/lbargaoanu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lbargaoanu/subscriptions","organizations_url":"https://api.github.com/users/lbargaoanu/orgs","repos_url":"https://api.github.com/users/lbargaoanu/repos","events_url":"https://api.github.com/users/lbargaoanu/events{/privacy}","received_events_url":"https://api.github.com/users/lbargaoanu/received_events","type":"User","site_admin":false},"created_at":"2016-02-13T17:09:18Z","updated_at":"2016-02-13T17:09:18Z","body":"You can have your entities implement an IHasAddress interface, do smth similar for you DTO-s and use Include or IncludeBase to reuse that mapping."}}