{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/3595","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/3595/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/3595/comments","events_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/3595/events","html_url":"https://github.com/aspnet/EntityFramework/issues/3595","id":113956324,"number":3595,"title":"Group By Null Reference Exception","user":{"login":"brent-russell","id":11100081,"avatar_url":"https://avatars.githubusercontent.com/u/11100081?v=3","gravatar_id":"","url":"https://api.github.com/users/brent-russell","html_url":"https://github.com/brent-russell","followers_url":"https://api.github.com/users/brent-russell/followers","following_url":"https://api.github.com/users/brent-russell/following{/other_user}","gists_url":"https://api.github.com/users/brent-russell/gists{/gist_id}","starred_url":"https://api.github.com/users/brent-russell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brent-russell/subscriptions","organizations_url":"https://api.github.com/users/brent-russell/orgs","repos_url":"https://api.github.com/users/brent-russell/repos","events_url":"https://api.github.com/users/brent-russell/events{/privacy}","received_events_url":"https://api.github.com/users/brent-russell/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/aspnet/EntityFramework/labels/bug","name":"bug","color":"f7c6c7"},{"url":"https://api.github.com/repos/aspnet/EntityFramework/labels/pri0","name":"pri0","color":"e11d21"}],"state":"open","locked":false,"assignee":{"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},"milestone":{"url":"https://api.github.com/repos/aspnet/EntityFramework/milestones/7","html_url":"https://github.com/aspnet/EntityFramework/milestones/7.0.0","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/milestones/7/labels","id":666128,"number":7,"title":"7.0.0","description":"","creator":{"login":"rowanmiller","id":4741851,"avatar_url":"https://avatars.githubusercontent.com/u/4741851?v=3","gravatar_id":"","url":"https://api.github.com/users/rowanmiller","html_url":"https://github.com/rowanmiller","followers_url":"https://api.github.com/users/rowanmiller/followers","following_url":"https://api.github.com/users/rowanmiller/following{/other_user}","gists_url":"https://api.github.com/users/rowanmiller/gists{/gist_id}","starred_url":"https://api.github.com/users/rowanmiller/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rowanmiller/subscriptions","organizations_url":"https://api.github.com/users/rowanmiller/orgs","repos_url":"https://api.github.com/users/rowanmiller/repos","events_url":"https://api.github.com/users/rowanmiller/events{/privacy}","received_events_url":"https://api.github.com/users/rowanmiller/received_events","type":"User","site_admin":false},"open_issues":196,"closed_issues":2,"state":"open","created_at":"2014-05-21T19:25:32Z","updated_at":"2015-10-30T19:56:24Z","due_on":null,"closed_at":null},"comments":3,"created_at":"2015-10-29T00:45:32Z","updated_at":"2015-10-30T20:24:25Z","closed_at":null,"body":"Beta8\r\n\r\nThe following query throws a null ref exception caused by the group by expression. Without the group by expression, the query runs fine. It doesn't matter what's in the select portion.\r\n\r\n```C#\r\nvar q0 = from instance in this.DbContext.ExamInstances\r\n\t\t join question in this.DbContext.ExamInstanceQuestions\r\n\t\t\ton instance.Id equals question.ExamInstanceId\r\n\t\t where instance.Id == 3\r\n\t\t group question by question.QuestionId into gQuestions\r\n\t\t select new\r\n\t\t {\r\n\t\t\t Key = gQuestions.Key,\r\n\t\t\t MaxDate = gQuestions.Max(q => q.UtcDateUpdated)\r\n\t\t };\r\n```\r\n\r\n```\r\nResult StackTrace:\t\r\nat Microsoft.Data.Entity.Query.QueryResultScope._GetResult[TResult](IQuerySource querySource)\r\n   at lambda_method(Closure , QueryResultScope )\r\n   at System.Linq.Lookup`2.Create[TSource](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)\r\n   at System.Linq.GroupedEnumerable`3.GetEnumerator()\r\n   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()\r\n   at System.Linq.Enumerable.<SelectManyIterator>d__1`2.MoveNext()\r\n   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()\r\n   at Microsoft.Data.Entity.Query.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()\r\n   at System.Linq.Buffer`1..ctor(IEnumerable`1 source)\r\n   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)\r\n\r\nResult Message:\tObject reference not set to an instance of an object.\r\n```\r\n\r\nThere's nothing really special about the model here. I'm running it against the SqlServer in-memory DB with a test data set in the thousands."},"comment":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/comments/152643058","html_url":"https://github.com/aspnet/EntityFramework/issues/3595#issuecomment-152643058","issue_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/3595","id":152643058,"user":{"login":"rowanmiller","id":4741851,"avatar_url":"https://avatars.githubusercontent.com/u/4741851?v=3","gravatar_id":"","url":"https://api.github.com/users/rowanmiller","html_url":"https://github.com/rowanmiller","followers_url":"https://api.github.com/users/rowanmiller/followers","following_url":"https://api.github.com/users/rowanmiller/following{/other_user}","gists_url":"https://api.github.com/users/rowanmiller/gists{/gist_id}","starred_url":"https://api.github.com/users/rowanmiller/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rowanmiller/subscriptions","organizations_url":"https://api.github.com/users/rowanmiller/orgs","repos_url":"https://api.github.com/users/rowanmiller/repos","events_url":"https://api.github.com/users/rowanmiller/events{/privacy}","received_events_url":"https://api.github.com/users/rowanmiller/received_events","type":"User","site_admin":false},"created_at":"2015-10-30T20:24:25Z","updated_at":"2015-10-30T20:24:25Z","body":"Perfect, thanks!"}}