{"action":"created","issue":{"url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/659","labels_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/659/labels{/name}","comments_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/659/comments","events_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/659/events","html_url":"https://github.com/AutoMapper/AutoMapper/pull/659","id":53492765,"number":659,"title":"IQueryable mapper. Make ability to create query with Dto objects and execute query with real objects","user":{"login":"Venzhyk","id":1943601,"avatar_url":"https://avatars.githubusercontent.com/u/1943601?v=3","gravatar_id":"","url":"https://api.github.com/users/Venzhyk","html_url":"https://github.com/Venzhyk","followers_url":"https://api.github.com/users/Venzhyk/followers","following_url":"https://api.github.com/users/Venzhyk/following{/other_user}","gists_url":"https://api.github.com/users/Venzhyk/gists{/gist_id}","starred_url":"https://api.github.com/users/Venzhyk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Venzhyk/subscriptions","organizations_url":"https://api.github.com/users/Venzhyk/orgs","repos_url":"https://api.github.com/users/Venzhyk/repos","events_url":"https://api.github.com/users/Venzhyk/events{/privacy}","received_events_url":"https://api.github.com/users/Venzhyk/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2015-01-06T08:37:00Z","updated_at":"2015-04-10T12:27:17Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/AutoMapper/AutoMapper/pulls/659","html_url":"https://github.com/AutoMapper/AutoMapper/pull/659","diff_url":"https://github.com/AutoMapper/AutoMapper/pull/659.diff","patch_url":"https://github.com/AutoMapper/AutoMapper/pull/659.patch"},"body":"My idea is a query mapper. \r\n\r\nI propose to make ability to create query with Dto objects and execute query on real objects.\r\n\r\nExample:\r\nclass Order { Id; Name; }\r\nclass OrderDto { OrderId; ProductName; }\r\n\r\nWe have OData service that expose OrderDto object.\r\nOrderDto object is mapped to data base real entity Order that stored in database.\r\n\r\nOData protocol provide ability to apply some filters, select fields and make order statements on OrderDto objects.\r\n\r\nYou able to create query on client side like this: \r\n```csharp\r\nODataClient.OrderDtoCollection\r\n     .Where(o => o.ProductName.StartWith(\"Book\"))\r\n     .OrderBy(o => o.OrderId)\r\n     .Select(o => o.OrderId);\r\n```\r\nThis query will be serialized into string (URL), sended to server, deserealized and executed on server side collection of OrderDto objects.\r\n\r\nI want to be able to convert that query base element type from OrderDto  to Order and replace all properties in query.\r\nMap query above to:\r\n```csharp\r\nDbContext.OrderSet\r\n     .Where(o => o.Name.StartWith(\"Book\"))\r\n     .OrderBy(o => o.Id)\r\n     .Select(o => o.Id);\r\n// and project results back to dto objects\r\n```\r\n\r\nPlease look to tests:\r\nAutoMapperSamples/Mappers/Query\r\nAutoMapperSamples/Mappers/QuerySourceInjection\r\n\r\n\r\nNote: it's only prototype of idea\r\n"},"comment":{"url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/comments/91537119","html_url":"https://github.com/AutoMapper/AutoMapper/pull/659#issuecomment-91537119","issue_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/659","id":91537119,"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},"created_at":"2015-04-10T12:27:17Z","updated_at":"2015-04-10T12:27:17Z","body":"Igor,\n\n\nConsider looking at my pull request #690.  The fork is here: https://github.com/BlaiseD/AutoMapper  .\n\n\nIt handles mapping Expression<Func<IQueryable<UserModel>, IQueryable<UserModel>>> exp; to Expression<Func<IQueryable<User>, IQueryable<User>>> exp;\n\n\nIt also handles the string.Empty case and the nested properties.\n\n\nI think it provides the abstraction you're looking for where the Where filter, the IQueryable expression, and the include expressions are all defined against the DTO rather than the POCO (EF class).\n\n\nAlso if you're mapping the Where filter, the IQueryable expression, and the include expressions then you shouldn't need to return an IQuerable<T>. You can return a List<T> instead.\n\n\nOne thing Tyler Carlson also mentioned before though: when mapping value types to their nullable counter parts you still need to map to the nullable's Value property.\n\n\nHope this helps.\n\n[https://avatars2.githubusercontent.com/u/7595209?v=3&s=400]<https://github.com/BlaiseD/AutoMapper>\n\nBlaiseD/AutoMapper · GitHub\nAutoMapper - A convention-based object-object mapper in .NET.\nRead more...<https://github.com/BlaiseD/AutoMapper>\n\n\n\n________________________________\nFrom: Igor Venzhyk <notifications@github.com>\nSent: Friday, April 10, 2015 6:20 AM\nTo: AutoMapper/AutoMapper\nSubject: Re: [AutoMapper] IQueryable mapper. Make ability to create query with Dto objects and execute query with real objects (#659)\n\n\n@TylerCarlson1<https://github.com/TylerCarlson1>, thanks for your suggestion.\n\nI've tried to use ExpressionMapper in my QueryMapperVisitor:\nVenzhyk@e47ee86<https://github.com/Venzhyk/AutoMapper/commit/e47ee86cdff63cb5cdc35b138509b6dddd89edb8>\n\nHowever I met several issues/bugs in ExpressionMapper:\n\n  1.  ExpressionMapper cannot resolve expressions like this:\n\n o => o.ContactName == string.Empty;\n\n\nIt stucks on string.Empty and tries to find map for Empty property\n\n  1.  ExpressionMapper cannot resolve nested properties.\n\n public class OrderDto\n {\n        public string ContactName { get; set; }\n }\n\n    public class Order\n    {\n        public Customer Customer { get; set; }\n    }\n\n    public class Customer\n    {\n        public string Name { get; set; }\n    }\n\n// Plain property to nested works fine\nExpression<Func<OrderDto, bool>> dto = o => o.ContactName == \"Bob\";\nvar db = Mapper.Map<Expression<Func<Order, bool>>>(dto);\n\n// Nested property to plain throws exception. It cannot find propertyMap for Name property.\n// It Seems it tries to search only in Order-> OrderDto map, not in Customer->OrderDto\n Expression<Func<Order, bool>> db = o => o.Customer.Name == \"Bob\";\n var dto= Mapper.Map<Expression<Func<OrderDto, bool>>>(db);\n\n\n-\nReply to this email directly or view it on GitHub<https://github.com/AutoMapper/AutoMapper/pull/659#issuecomment-91507391>.\n"}}