{"action":"created","issue":{"url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/1216","repository_url":"https://api.github.com/repos/AutoMapper/AutoMapper","labels_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/1216/labels{/name}","comments_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/1216/comments","events_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/1216/events","html_url":"https://github.com/AutoMapper/AutoMapper/issues/1216","id":145267898,"number":1216,"title":"Flatten nested children using ProjectTo","user":{"login":"matt6502git","id":18219695,"avatar_url":"https://avatars.githubusercontent.com/u/18219695?v=3","gravatar_id":"","url":"https://api.github.com/users/matt6502git","html_url":"https://github.com/matt6502git","followers_url":"https://api.github.com/users/matt6502git/followers","following_url":"https://api.github.com/users/matt6502git/following{/other_user}","gists_url":"https://api.github.com/users/matt6502git/gists{/gist_id}","starred_url":"https://api.github.com/users/matt6502git/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matt6502git/subscriptions","organizations_url":"https://api.github.com/users/matt6502git/orgs","repos_url":"https://api.github.com/users/matt6502git/repos","events_url":"https://api.github.com/users/matt6502git/events{/privacy}","received_events_url":"https://api.github.com/users/matt6502git/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2016-04-01T19:43:15Z","updated_at":"2016-04-01T20:24:25Z","closed_at":null,"body":"Have been using AutoMapper for a couple of years but starting to dive deeper into the more advanced features of it and I'm having issues that I cannot resolve.\r\n\r\nSimple example for demo purposes:  5 tables....grandparent, parent, child, and 2 relation tables, grandparentParent and parentChild.   What I want is a list of grandparentviewmodels that have only the grandparent name, but also has a list of grandchild objects....not a list of parent objects....ie....\"give me the grandparent and all their grandchildren regardless of which parent they are a child of\".\r\n\r\nIn order to try to get this working, I have used the ConvertUsing method and have created a class that implements the ITypeConverter interface.   Everything builds, but I can't get the mapping to work....the breakpoints I am setting in the TypeConverter class do not get hit and I can't figure out what I am doing wrong.\r\n\r\nI created a stackoverflow question for this, but it isn't getting any action so hoping this forum helps.  [Here is the SO question] (http://stackoverflow.com/questions/36344338/flatten-linq-automapper-projectto-nested-children).  And below are snippets of the code I have:\r\n\r\n```\r\npublic class GrandparentConverter : ITypeConverter<Grandparent, GrandparentViewModel>\r\n{\r\n    public GrandparentViewModel Convert(ResolutionContext context)\r\n    {\r\n        var entities = context.SourceValue as Grandparent;\r\n\r\n        return entities\r\n            .Select(x => new GrandparentViewModel\r\n            {\r\n                GrandparentId = x.GrandparentId,\r\n                Name = x.Name,\r\n                Grandchildren = AutoMapper.Mapper.Map<IEnumerable<Parent>, List<ChildViewModel>>(x.Parents)\r\n            }).ToList();\r\n\r\n        //return new GrandparentViewModel\r\n        //{\r\n        //    GrandparentId = entities.GrandparentId,\r\n        //    Name = entities.Name,\r\n        //    Grandchildren = entities.Parents.SelectMany(x => x.Children.Select(y => new ChildViewModel\r\n        //    {\r\n        //        ChildId = y.ChildId,\r\n        //        Name = y.Name\r\n        //    }).ToList()).ToList()\r\n        //};\r\n    }\r\n}\r\n\r\n\r\npublic class ChildConverter : ITypeConverter<IEnumerable<Parent>, List<ChildViewModel>>\r\n{\r\n    public List<ChildViewModel> Convert(ResolutionContext context)\r\n    {\r\n        var entities = context.SourceValue as IEnumerable<Parent>;\r\n\r\n        return entities\r\n            .SelectMany(x => x.Children)\r\n            .Select(x => new ChildViewModel\r\n            {\r\n                ChildId = x.ChildId,\r\n                Name = x.Name\r\n            }).ToList();\r\n    }\r\n} \r\n\r\n....surrounding code removed as it isn't relevant....\r\nMapperConfiguration mapper = new MapperConfiguration(cfg =>\r\n        {\r\n            cfg.CreateMap<Child, ChildViewModel>();\r\n            cfg.CreateMap<IEnumerable<Parent>, List<ChildViewModel>>().ConvertUsing<ChildConverter>();\r\n\r\n            cfg.CreateMap<Grandparent, GrandparentViewModel>();\r\n            cfg.CreateMap<IEnumerable<Grandparent>, List<GrandparentViewModel>>().ConvertUsing<GrandparentConverter>();\r\n        });\r\n\r\n        FamilyEntities db = new FamilyEntities();\r\n        List<GrandparentViewModel> entities = db.Set<Grandparent>()\r\n            .Where(x => x.GrandparentId == 1)\r\n            .ProjectTo<GrandparentViewModel>(mapper)\r\n            .ToList();\r\n```"},"comment":{"url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/comments/204555218","html_url":"https://github.com/AutoMapper/AutoMapper/issues/1216#issuecomment-204555218","issue_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/1216","id":204555218,"user":{"login":"matt6502git","id":18219695,"avatar_url":"https://avatars.githubusercontent.com/u/18219695?v=3","gravatar_id":"","url":"https://api.github.com/users/matt6502git","html_url":"https://github.com/matt6502git","followers_url":"https://api.github.com/users/matt6502git/followers","following_url":"https://api.github.com/users/matt6502git/following{/other_user}","gists_url":"https://api.github.com/users/matt6502git/gists{/gist_id}","starred_url":"https://api.github.com/users/matt6502git/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matt6502git/subscriptions","organizations_url":"https://api.github.com/users/matt6502git/orgs","repos_url":"https://api.github.com/users/matt6502git/repos","events_url":"https://api.github.com/users/matt6502git/events{/privacy}","received_events_url":"https://api.github.com/users/matt6502git/received_events","type":"User","site_admin":false},"created_at":"2016-04-01T20:24:25Z","updated_at":"2016-04-01T20:24:25Z","body":"Yes, it works if I do not use AutoMapper's ProjectTo.  \r\n\r\nThis is how I have always used AutoMapper in the past, but the problem with this approach is that I have tried to abstract away the select logic so I can have multiple and different view model classes returned based on business function.   I was really hoping that this was going to be the savior to keep my away from the traditional method bloat that happens with returning nearly identical business objects."}}