{"action":"opened","issue":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/4635","repository_url":"https://api.github.com/repos/aspnet/EntityFramework","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/4635/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/4635/comments","events_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/4635/events","html_url":"https://github.com/aspnet/EntityFramework/issues/4635","id":136074108,"number":4635,"title":"Select uses INNER JOIN instead of LEFT JOIN","user":{"login":"cbmek","id":1478006,"avatar_url":"https://avatars.githubusercontent.com/u/1478006?v=3","gravatar_id":"","url":"https://api.github.com/users/cbmek","html_url":"https://github.com/cbmek","followers_url":"https://api.github.com/users/cbmek/followers","following_url":"https://api.github.com/users/cbmek/following{/other_user}","gists_url":"https://api.github.com/users/cbmek/gists{/gist_id}","starred_url":"https://api.github.com/users/cbmek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cbmek/subscriptions","organizations_url":"https://api.github.com/users/cbmek/orgs","repos_url":"https://api.github.com/users/cbmek/repos","events_url":"https://api.github.com/users/cbmek/events{/privacy}","received_events_url":"https://api.github.com/users/cbmek/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-02-24T14:18:50Z","updated_at":"2016-02-24T14:18:50Z","closed_at":null,"body":"## The case\r\nLets say we have two objects with nullable relation one-to-many:\r\n\r\n```csharp\r\npublic class Post {\r\n    public int Id { get; set; }\r\n    public string Title{ get; set; }\r\n    public virtual ICollection<Comment> Comments { get; set; }\r\n}\r\n```\r\n\r\n```csharp\r\npublic class Comment {\r\n    public int Id { get; set; }\r\n    public string Content { get; set; }\r\n    public int? PostId {get; set; }\r\n    public virtual Post Post { get; set; }\r\n}\r\n```\r\n\r\nWe want to get all the comments with it's Posts (if any).\r\n\r\n```csharp\r\nvar all = _context.Comments.Include(m => m.Post).ToList();\r\n```\r\n\r\nit will do a single query, with LEFT JOIN, and results are correct. If Comments is not assigned to Post then Post property will equal null - PERFECT!\r\n\r\n## The problem\r\n...but let's use Select, like this:\r\n\r\n```csharp\r\nvar all = _context.Comments.Include(m => m.Post).Select(m => new { \r\n    Something = m.Content, \r\n    PostTitle = Post != null ? Post.Title : \"NO POST\"  \r\n});\r\n```\r\n\r\nand strange thing happen, the SQL query uses INNER JOIN, so we end **only **with Comments witch has Post assigned. In my opinion it should still use LEFT JOIN.\r\n\r\n## Temp solution\r\nThe only way to make it to work like it should now is to do the ToList() before Select():\r\n\r\n```csharp\r\nvar all = _context.Comments.Include(m => m.Post).ToList().Select(m => new { \r\n    Something = m.Content, \r\n    PostTitle = Post != null ? Post.Title : \"NO POST\"  \r\n});\r\n```\r\n"}}