{"action":"created","issue":{"url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/1916","repository_url":"https://api.github.com/repos/AutoMapper/AutoMapper","labels_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/1916/labels{/name}","comments_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/1916/comments","events_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/1916/events","html_url":"https://github.com/AutoMapper/AutoMapper/pull/1916","id":201415276,"number":1916,"title":"Provide an alternative to using ProjectTo() and static initialization…  ","user":{"login":"BlaiseD","id":7595209,"avatar_url":"https://avatars.githubusercontent.com/u/7595209?v=3","gravatar_id":"","url":"https://api.github.com/users/BlaiseD","html_url":"https://github.com/BlaiseD","followers_url":"https://api.github.com/users/BlaiseD/followers","following_url":"https://api.github.com/users/BlaiseD/following{/other_user}","gists_url":"https://api.github.com/users/BlaiseD/gists{/gist_id}","starred_url":"https://api.github.com/users/BlaiseD/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BlaiseD/subscriptions","organizations_url":"https://api.github.com/users/BlaiseD/orgs","repos_url":"https://api.github.com/users/BlaiseD/repos","events_url":"https://api.github.com/users/BlaiseD/events{/privacy}","received_events_url":"https://api.github.com/users/BlaiseD/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":31,"created_at":"2017-01-17T21:49:11Z","updated_at":"2017-02-16T20:54:09Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/AutoMapper/AutoMapper/pulls/1916","html_url":"https://github.com/AutoMapper/AutoMapper/pull/1916","diff_url":"https://github.com/AutoMapper/AutoMapper/pull/1916.diff","patch_url":"https://github.com/AutoMapper/AutoMapper/pull/1916.patch"},"body":"### Goal: Provide an alternative to using ProjectTo() and static initialization for ASP.NET Core - instead using instance initialization with expression mapping.\r\n\r\n- Maps expressions involving flattened (TModel) properties (when the navigation property has been removed from the view model) to their corresponding (TData) navigation properties. e.g. CourseModel.DepartmentName from the model expression becomes Course.Department in the data expression.\r\n```\r\npublic class CourseModel\r\n    {\r\n        public int CourseID { get; set; }\r\n\r\n        public int DepartmentID { get; set; }\r\n        public string DepartmentName { get; set; }\r\n    }\r\npublic class Course\r\n    {\r\n        public int CourseID { get; set; }\r\n\r\n        public int DepartmentID { get; set; }\r\n        public Department Department { get; set; }\r\n    }\r\n\r\n    public class Department\r\n    {\r\n        public int DepartmentID { get; set; }\r\n        public string Name { get; set; }\r\n    }\r\n```\r\n- Fixes issues #1821, #1886 and #1893. I agree that the use case for deflattening (#1893) is not clear but it works.\r\n- Fixes miscellaneous expression mapping issues.  Please see the tests under XpressionMapperTests.  Many do not succeed with 5.2 code - usually when there is an extension method in the expression.\r\n\r\nIt maps all the followimg expression from TModel to TData - see the StoreHelpers class in the ContosoUniversity.Repositories project (Samples Solution folder). All calls to map expressions and objects are in this file.\r\n\r\n- Expression<Func<TModel, bool>> filter\r\n- Expression<Func<IQueryable<TModel>, IQueryable<TModel>>> queryFunc\r\n- ICollection<Expression<Func<IQueryable<TModel>, IIncludableQueryable<TModel, object>>>> includeProperties\r\n\r\nThe Contoso example [here](https://github.com/BlaiseD/XpressionMapper.NetCore) shows the solution in action. It is all generics, AutoMapper and EF - hardly any reference to concrete types.\r\n\r\nI requested PR #704 canceled a year and a half ago because I didn't think the value was clear but I believe this helps now. I don't want to replace the current one. Maybe they can run side my side with different helpers? Mapper.MapExpression vs Mapper.Map?\r\n\r\nTo test my implementation please uncomment \"//#define XPRESSIONMAPPER\" at the top of ExpressionMapper.cs.\r\n\r\nMy implementation does fail one test as of this writing.  **Can_map_flattened_properties** in ExpressionConversion.cs.\r\n\r\n`var config = new MapperConfiguration(cfg => cfg.CreateMap<Source, Dest>().ForMember(dest => dest.ChildValue, opt => opt.MapFrom(src => src.Child.Value)));` works but\r\n`var config = new MapperConfiguration(cfg => cfg.CreateMap<Source, Dest>());` fails.\r\n\r\nChildValue is being mapped somehow by concatenating Child.Value - I haven't figured out the source yet - the property maps only show the relationship for the first configuration.\r\nXpressionMapperTests and ExpressionMapping tests all pass.\r\n\r\nPlease let me know.  It will be great if it can be part of AutoMapper.\r\n\r\nThanks,\r\nBlaise\r\n"},"comment":{"url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/comments/280457000","html_url":"https://github.com/AutoMapper/AutoMapper/pull/1916#issuecomment-280457000","issue_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/1916","id":280457000,"user":{"login":"jbogard","id":104498,"avatar_url":"https://avatars.githubusercontent.com/u/104498?v=3","gravatar_id":"","url":"https://api.github.com/users/jbogard","html_url":"https://github.com/jbogard","followers_url":"https://api.github.com/users/jbogard/followers","following_url":"https://api.github.com/users/jbogard/following{/other_user}","gists_url":"https://api.github.com/users/jbogard/gists{/gist_id}","starred_url":"https://api.github.com/users/jbogard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbogard/subscriptions","organizations_url":"https://api.github.com/users/jbogard/orgs","repos_url":"https://api.github.com/users/jbogard/repos","events_url":"https://api.github.com/users/jbogard/events{/privacy}","received_events_url":"https://api.github.com/users/jbogard/received_events","type":"User","site_admin":false},"created_at":"2017-02-16T20:54:08Z","updated_at":"2017-02-16T20:54:08Z","body":"Regions and field names. Like I said, no big deal.\n\nOn Thu, Feb 16, 2017 at 2:23 PM, Blaise Taylor <notifications@github.com>\nwrote:\n\n> @jbogard <https://github.com/jbogard> That's more than cool. I'll update\n> the Wiki for new functionality - seems like I have the permissions.\n> Interested to know what the coding style issues are.\n>\n> Thanks.\n>\n> —\n> You are receiving this because you were mentioned.\n> Reply to this email directly, view it on GitHub\n> <https://github.com/AutoMapper/AutoMapper/pull/1916#issuecomment-280448223>,\n> or mute the thread\n> <https://github.com/notifications/unsubscribe-auth/AAGYMkTybgsU1JaUUV749KuLz_JUz0Beks5rdLAlgaJpZM4LmNHe>\n> .\n>\n"}}
{"actor":{"display_login":"jbogard"}}