{"action":"created","issue":{"url":"https://api.github.com/repos/OData/odata.net/issues/533","repository_url":"https://api.github.com/repos/OData/odata.net","labels_url":"https://api.github.com/repos/OData/odata.net/issues/533/labels{/name}","comments_url":"https://api.github.com/repos/OData/odata.net/issues/533/comments","events_url":"https://api.github.com/repos/OData/odata.net/issues/533/events","html_url":"https://github.com/OData/odata.net/issues/533","id":147464069,"number":533,"title":"Linq is a leaky abstraction, needs some documentation or a change with some http 404 errors","user":{"login":"nicenemo","id":2677108,"avatar_url":"https://avatars.githubusercontent.com/u/2677108?v=3","gravatar_id":"","url":"https://api.github.com/users/nicenemo","html_url":"https://github.com/nicenemo","followers_url":"https://api.github.com/users/nicenemo/followers","following_url":"https://api.github.com/users/nicenemo/following{/other_user}","gists_url":"https://api.github.com/users/nicenemo/gists{/gist_id}","starred_url":"https://api.github.com/users/nicenemo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nicenemo/subscriptions","organizations_url":"https://api.github.com/users/nicenemo/orgs","repos_url":"https://api.github.com/users/nicenemo/repos","events_url":"https://api.github.com/users/nicenemo/events{/privacy}","received_events_url":"https://api.github.com/users/nicenemo/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-04-11T15:26:18Z","updated_at":"2016-04-26T04:13:38Z","closed_at":"2016-04-26T04:13:38Z","body":"Searching for a non existing element using  a primary key and and search for an element using a primary key and andother property using LINQ produce different urls but also different results.\r\n\r\n\r\n### Assemblies affected\r\n OData .Net lib 6.15-beta\r\nNote: We are using OLingo on the serverside.\r\n\r\n\r\n### Reproduce steps\r\nObserver the following two tests that only differe in the where clause.\r\n\r\n- The first test is equivalent to a `ctx.Documents.Bykey(sessionId)` call\r\n- The first produces a http 404  error.\r\n- The second produces an url with a a $filter clause.\r\n- The second results in an Empty set.\r\n\r\n```\r\n    /// <summary>\r\n    /// Find non existing session.\r\n    /// </summary>\r\n    [Fact()]\r\n    public void FindNonExistingSessionWithOnlySessionIdinWhereClauseThrowsException()\r\n    {\r\n      var ctx = CreateContext();\r\n      var fakedSessionId = PostFakeSessions(ctx, 1).Single();\r\n      try\r\n      {\r\n\r\n        Action action = () =>\r\n        {\r\n          var nonExistingSessionId = Guid.NewGuid().ToString();\r\n          var session = (from ses in ctx.Sessions\r\n                         where ses.SessionId == nonExistingSessionId\r\n                         select ses).ToArray().FirstOrDefault();\r\n        };\r\n\r\n        Assert.Throws<DataServiceQueryException>(action);\r\n\r\n      }\r\n      finally\r\n      {\r\n        DeleteDocuments(ctx, fakedSessionId);\r\n      }\r\n    }\r\n\r\n    /// <summary>\r\n    /// Find non existing session.\r\n    /// </summary>\r\n    [Fact()]\r\n    public void FindNonExistingSession()\r\n    {\r\n      var ctx = CreateContext();\r\n      var fakedSessionId = PostFakeSessions(ctx, 1).Single();\r\n      try\r\n      {\r\n\r\n        Action action = () =>\r\n        {\r\n          var nonExistingSessionId = Guid.NewGuid().ToString();\r\n          var session = (from ses in ctx.Sessions\r\n                         where ses.SessionId == nonExistingSessionId && ses.CreationDate.Value.Hour>0\r\n                         select ses).ToArray().FirstOrDefault();\r\n          Assert.Null(session);\r\n        };\r\n\r\n        action();\r\n\r\n      }\r\n      finally\r\n      {\r\n        DeleteDocuments(ctx, fakedSessionId);\r\n      }\r\n    }\r\n\r\n```\r\n### Expected result\r\nWarn programmers for this in the documentation or catch 404 silently and produce an empty set clientside.\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/OData/odata.net/issues/comments/214607766","html_url":"https://github.com/OData/odata.net/issues/533#issuecomment-214607766","issue_url":"https://api.github.com/repos/OData/odata.net/issues/533","id":214607766,"user":{"login":"markdstafford","id":1216569,"avatar_url":"https://avatars.githubusercontent.com/u/1216569?v=3","gravatar_id":"","url":"https://api.github.com/users/markdstafford","html_url":"https://github.com/markdstafford","followers_url":"https://api.github.com/users/markdstafford/followers","following_url":"https://api.github.com/users/markdstafford/following{/other_user}","gists_url":"https://api.github.com/users/markdstafford/gists{/gist_id}","starred_url":"https://api.github.com/users/markdstafford/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/markdstafford/subscriptions","organizations_url":"https://api.github.com/users/markdstafford/orgs","repos_url":"https://api.github.com/users/markdstafford/repos","events_url":"https://api.github.com/users/markdstafford/events{/privacy}","received_events_url":"https://api.github.com/users/markdstafford/received_events","type":"User","site_admin":false},"created_at":"2016-04-26T04:13:37Z","updated_at":"2016-04-26T04:13:37Z","body":"They always say it's best to preface any bad news with a compliment, right? Thank you for submitting all of the issues recently (and in the past as well). It's good to have vocal people in our community.\r\n\r\nIn this particular case, I'm going to close this issue as \"by design\". If you want to discuss further, it's perfectly fine to reopen the issue, but let me try to explain a bit more than just saying \"by design\".\r\n\r\nLINQ providers are interesting beasts, and as you've pointed out they don't map up 100% to OData query semantics. Overall we think it's helpful to .NET developers as they don't need to learn OData query syntax if they know LINQ. But that means we have to make calls about how to translate certain LINQ queries. Years ago we decided that if the only thing the where clause contains is an equality match on the key property, we should translate that to normal key syntax. Anything more complicated should just get stuffed into the $filter expression. IOW we consciously made the decision not to extricate any key properties since things get complicated quickly (e.g., ||, etc) and the value is low. The point here is that the different URLs you're seeing generated are by design.\r\n\r\nWe could always improve at documentation, but at this point we are focused on an upcoming breaking changes release (things tracked against the 7.0 milestone) and we have a hard date to get that out, so addressing this in documentation is low on our priority list right now. We would happily accept pull requests to our documentation (https://github.com/OData/odata.github.io) as well, though, so if you have time to write something up we'd love to reopen this issue and get it fixed properly.\r\n\r\nI know that's not the answer you want to hear, but hopefully at least getting the explanation helps."}}