{"action":"created","issue":{"url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/649","labels_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/649/labels{/name}","comments_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/649/comments","events_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/649/events","html_url":"https://github.com/AutoMapper/AutoMapper/pull/649","id":51944672,"number":649,"title":"Fix ExpressionMapper error for sub property expression conversion","user":{"login":"TylerCarlson1","id":6801536,"avatar_url":"https://avatars.githubusercontent.com/u/6801536?v=3","gravatar_id":"","url":"https://api.github.com/users/TylerCarlson1","html_url":"https://github.com/TylerCarlson1","followers_url":"https://api.github.com/users/TylerCarlson1/followers","following_url":"https://api.github.com/users/TylerCarlson1/following{/other_user}","gists_url":"https://api.github.com/users/TylerCarlson1/gists{/gist_id}","starred_url":"https://api.github.com/users/TylerCarlson1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TylerCarlson1/subscriptions","organizations_url":"https://api.github.com/users/TylerCarlson1/orgs","repos_url":"https://api.github.com/users/TylerCarlson1/repos","events_url":"https://api.github.com/users/TylerCarlson1/events{/privacy}","received_events_url":"https://api.github.com/users/TylerCarlson1/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":15,"created_at":"2014-12-15T03:12:31Z","updated_at":"2015-07-11T19:26:44Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/AutoMapper/AutoMapper/pulls/649","html_url":"https://github.com/AutoMapper/AutoMapper/pull/649","diff_url":"https://github.com/AutoMapper/AutoMapper/pull/649.diff","patch_url":"https://github.com/AutoMapper/AutoMapper/pull/649.patch"},"body":"Fix Issues with Expression Mappings #648 when use properties which types have their own mappings that need to be converted over.\r\n\r\nMultiple scenarios have been solved for now including the original problem.\r\nIssue still lies with multiple level same type one to many relationships. (One to many relationships of different types work fine)\r\nEx: ```Tools.Any(t => t.SubTools.Any(t => t.ID == id))``` will fail to convert over cause Any function will still be assuming ToolDTO instead of Tool as generic parameter type."},"comment":{"url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/comments/120653576","html_url":"https://github.com/AutoMapper/AutoMapper/pull/649#issuecomment-120653576","issue_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/649","id":120653576,"user":{"login":"TylerCarlson1","id":6801536,"avatar_url":"https://avatars.githubusercontent.com/u/6801536?v=3","gravatar_id":"","url":"https://api.github.com/users/TylerCarlson1","html_url":"https://github.com/TylerCarlson1","followers_url":"https://api.github.com/users/TylerCarlson1/followers","following_url":"https://api.github.com/users/TylerCarlson1/following{/other_user}","gists_url":"https://api.github.com/users/TylerCarlson1/gists{/gist_id}","starred_url":"https://api.github.com/users/TylerCarlson1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TylerCarlson1/subscriptions","organizations_url":"https://api.github.com/users/TylerCarlson1/orgs","repos_url":"https://api.github.com/users/TylerCarlson1/repos","events_url":"https://api.github.com/users/TylerCarlson1/events{/privacy}","received_events_url":"https://api.github.com/users/TylerCarlson1/received_events","type":"User","site_admin":false},"created_at":"2015-07-11T19:26:44Z","updated_at":"2015-07-11T19:26:44Z","body":"My implementation also separates concerns much the same way yours does.  The Query doesn't know of AutoMapper or business Models when it gets called.\r\nLike ```db.Accounts.Project().To<AccountModel>()``` will not pass Account model into the query it will send an automapper generated select statement to EF to translate to SQL.\r\n\r\nAnd for your examples given before (Translated to UseAsDataSource implementation):\r\n```\r\ndb.Users.UseAsDataSource().For<UserModel>().OrderBy<UserModel>(s => s.Id).ThenBy<UserModel>(s => s.FullName)\r\n```\r\nTranslates\r\n```OrderBy<UserModel>(s => s.Id)``` to ```OrderBy<User>(s => s.Id)```\r\n```ThenBy<UserModel>(s => s.FullName)``` to ```ThenBy<User>(s => s.Account == null ? string.Empty : string.Concat(s.Account.FirstName, \" \", s.Account.LastName))```\r\nWill then call ```Projection().To<UserModel>()``` after all the Ordering to get the benefit of having a select statement do the conversion.\r\nThis is because return type didn't change from UserModel to anything else.\r\nEquivalent Translation\r\n```\r\ndb.Users.OrderBy<User>(s => s.Id).ThenBy<User>(s => s.Account == null ? string.Empty : string.Concat(s.Account.FirstName, \" \", s.Account.LastName)).Project().To<UserModel>()\r\n```\r\n\r\nSelect Example (Translated to UseAsDataSource implementation)\r\n```\r\ndb.Users.UseAsDataSource().For<UserModel>().Select<UserModel>(s => (object)s.ThingModels.Select<ThingsModel>(x => x.BarModel))\r\n```\r\nTranslates\r\n```Select<UserModel>(s => (object)s.ThingModels.Select<ThingsModel>(x => x.BarModel))``` to ``Select<User>(s => (object)s.Things.Select<Things>(x => x.Bar))```\r\nNo Projection is done because return type is now object and not UserModel, so there's no reason to project.\r\nEquivalent Translation\r\n```\r\ndb.Users).Select<User>(s => (object)s.Thing.Select<Things>(x => x.Bar))\r\n```\r\n\r\nProject().To() is to provide the benifits of it when applicable, but maybe there should be an option to not project and use Map instead?\r\nI see from your DateCreated Mapping it uses External method call, which would definitely not convert from EF to T-SQL and make projection impossible.  Also you have include property maps, which I do not have, because Projection will handle including them in the query to the database."}}