{"action":"created","issue":{"url":"https://api.github.com/repos/chaowlert/Mapster/issues/10","repository_url":"https://api.github.com/repos/chaowlert/Mapster","labels_url":"https://api.github.com/repos/chaowlert/Mapster/issues/10/labels{/name}","comments_url":"https://api.github.com/repos/chaowlert/Mapster/issues/10/comments","events_url":"https://api.github.com/repos/chaowlert/Mapster/issues/10/events","html_url":"https://github.com/chaowlert/Mapster/issues/10","id":256411826,"number":10,"title":"Mapping for all derived types","user":{"login":"Laban1","id":9595654,"avatar_url":"https://avatars0.githubusercontent.com/u/9595654?v=4","gravatar_id":"","url":"https://api.github.com/users/Laban1","html_url":"https://github.com/Laban1","followers_url":"https://api.github.com/users/Laban1/followers","following_url":"https://api.github.com/users/Laban1/following{/other_user}","gists_url":"https://api.github.com/users/Laban1/gists{/gist_id}","starred_url":"https://api.github.com/users/Laban1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Laban1/subscriptions","organizations_url":"https://api.github.com/users/Laban1/orgs","repos_url":"https://api.github.com/users/Laban1/repos","events_url":"https://api.github.com/users/Laban1/events{/privacy}","received_events_url":"https://api.github.com/users/Laban1/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2017-09-09T03:42:45Z","updated_at":"2017-09-11T14:13:53Z","closed_at":null,"author_association":"NONE","body":"Hi,\r\n\r\nI have a couple of base classes, ModelBase and ModelVmBase.  There are 50+ classes inheriting from each.  \r\n\r\nHere is the ModelBase (used by the EF objects).  It has two nested User properties:\r\n\r\n```\r\npublic class ModelBase \r\n{\r\n\tpublic virtual User CreatedByUser { get; set; } // The nested User object has a UserName property\r\n\tpublic virtual User UpdatedByUser { get; set; } // The nested User object has a UserName property\r\n}\r\n\r\n```\r\n\r\nHere is the ModelVmBase, which is the base class for the DTOs / VMs:\r\n```\r\npublic class ModelVmBase \r\n{\r\n\tpublic string CreatedByUserName { get; set; }\r\n\tpublic string UpdatedByUserName { get; set; }\r\n}\r\n```\r\nWhat I am trying to do is to map the nested UserName of the ModelBase to the corresponding UserName property in the ModelVmBase.  \r\n\r\nI know that I can do accomplish this with a specific mapping for each of the sub-classes, e.g.:\r\n```\r\nTypeAdapterConfig<Note, NoteVm>\r\n\t.NewConfig()\r\n\t.Map(dest => dest.UpdatedByUserName, src => src.UpdatedByUser.UserName)\r\n\t.Map(dest => dest.CreatedByUserName, src => src.CreatedByUser.UserName);\r\n```\r\n\r\nHowever, with 50+ inheriting classes, it would be much cleaner if I could just define this for the ModelBase and ModelVmBase:\r\n\r\n```\r\nTypeAdapterConfig<ModelBase, ModelVmBase>\r\n\t.NewConfig()\r\n\t.Map(dest => dest.UpdatedByUserName, src => src.UpdatedByUser.UserName)\r\n\t.Map(dest => dest.CreatedByUserName, src => src.CreatedByUser.UserName);\r\n\r\n```\r\n\r\nHowever, it does not work when doing it on the base classes (=the CreatedByUserName and UpdatedByUserName are not getting mapped).  Is there a way to make this work w/o doing it for each subclass?\r\n\r\nThanks.\r\n"},"comment":{"url":"https://api.github.com/repos/chaowlert/Mapster/issues/comments/328542145","html_url":"https://github.com/chaowlert/Mapster/issues/10#issuecomment-328542145","issue_url":"https://api.github.com/repos/chaowlert/Mapster/issues/10","id":328542145,"user":{"login":"chaowlert","id":5763993,"avatar_url":"https://avatars2.githubusercontent.com/u/5763993?v=4","gravatar_id":"","url":"https://api.github.com/users/chaowlert","html_url":"https://github.com/chaowlert","followers_url":"https://api.github.com/users/chaowlert/followers","following_url":"https://api.github.com/users/chaowlert/following{/other_user}","gists_url":"https://api.github.com/users/chaowlert/gists{/gist_id}","starred_url":"https://api.github.com/users/chaowlert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chaowlert/subscriptions","organizations_url":"https://api.github.com/users/chaowlert/orgs","repos_url":"https://api.github.com/users/chaowlert/repos","events_url":"https://api.github.com/users/chaowlert/events{/privacy}","received_events_url":"https://api.github.com/users/chaowlert/received_events","type":"User","site_admin":false},"created_at":"2017-09-11T14:13:53Z","updated_at":"2017-09-11T14:13:53Z","author_association":"OWNER","body":"Isn't that because of your mapping code? Change your mapping code to\r\n\r\n```\r\nTypeAdapterConfig<ModelBase, ModelVmBase>\r\n\t.NewConfig()\r\n\t.Map(dest => dest.UpdatedByUserName, src => src.UpdatedByUser == null ? null : src.UpdatedByUser.UserName)\r\n\t.Map(dest => dest.CreatedByUserName, src =>  src.UpdatedByUser == null ? null : src.CreatedByUser.UserName);\r\n```"}}
{"actor":{"display_login":"chaowlert"}}