{"action":"closed","issue":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/5144","repository_url":"https://api.github.com/repos/aspnet/EntityFramework","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/5144/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/5144/comments","events_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/5144/events","html_url":"https://github.com/aspnet/EntityFramework/issues/5144","id":150212930,"number":5144,"title":"Sqlite :: subquery with SingleOrDefault returning multiple results doesn't throw in Sqlite","user":{"login":"maumar","id":1591930,"avatar_url":"https://avatars.githubusercontent.com/u/1591930?v=3","gravatar_id":"","url":"https://api.github.com/users/maumar","html_url":"https://github.com/maumar","followers_url":"https://api.github.com/users/maumar/followers","following_url":"https://api.github.com/users/maumar/following{/other_user}","gists_url":"https://api.github.com/users/maumar/gists{/gist_id}","starred_url":"https://api.github.com/users/maumar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maumar/subscriptions","organizations_url":"https://api.github.com/users/maumar/orgs","repos_url":"https://api.github.com/users/maumar/repos","events_url":"https://api.github.com/users/maumar/events{/privacy}","received_events_url":"https://api.github.com/users/maumar/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-04-21T22:49:47Z","updated_at":"2016-04-22T18:19:43Z","closed_at":"2016-04-22T18:19:42Z","body":"Query:\r\n\r\n```cs\r\nfrom e1 in ctx.Set<Employee>()\r\nwhere ctx.Set<Employee>().Select(e2 => e2.EmployeeID).SingleOrDefault(e2 => e2 != e1.ReportsTo) == 0\r\nselect e1;\r\n```\r\n\r\nThis gets translated to:\r\n\r\n```\r\nSELECT [e1].[EmployeeID], [e1].[City], [e1].[Country], [e1].[FirstName], [e1].[ReportsTo], [e1].[Title]\r\nFROM [Employees] AS [e1]\r\nWHERE (\r\n    SELECT TOP(2) [e2].[EmployeeID]\r\n    FROM [Employees] AS [e2]\r\n    WHERE ([e2].[EmployeeID] <> [e1].[ReportsTo]) OR [e1].[ReportsTo] IS NULL\r\n) = 0\r\n```\r\n\r\nOn SQL Server this is invalid query because the subquery returns multiple results and is later compared with a scalar, which somewhat simulates SingleOrDefault, however on Sqlite this is allowed (returning first row and therefore resulting in FirstOrDefault behavior instead)\r\n\r\nWe could do a few things about it:\r\n- leave as is,\r\n- always force client evaluation for SingleOrDefault,\r\n- issue a warning in a log, just like we do for Equals(object)."}}