{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/6821","repository_url":"https://api.github.com/repos/aspnet/EntityFramework","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/6821/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/6821/comments","events_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/6821/events","html_url":"https://github.com/aspnet/EntityFramework/issues/6821","id":184064977,"number":6821,"title":"List of related entities not loading (null reference exception)","user":{"login":"rykr","id":108892,"avatar_url":"https://avatars.githubusercontent.com/u/108892?v=3","gravatar_id":"","url":"https://api.github.com/users/rykr","html_url":"https://github.com/rykr","followers_url":"https://api.github.com/users/rykr/followers","following_url":"https://api.github.com/users/rykr/following{/other_user}","gists_url":"https://api.github.com/users/rykr/gists{/gist_id}","starred_url":"https://api.github.com/users/rykr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rykr/subscriptions","organizations_url":"https://api.github.com/users/rykr/orgs","repos_url":"https://api.github.com/users/rykr/repos","events_url":"https://api.github.com/users/rykr/events{/privacy}","received_events_url":"https://api.github.com/users/rykr/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-10-19T20:26:02Z","updated_at":"2016-10-20T16:38:14Z","closed_at":"2016-10-20T16:38:14Z","body":"I have this pattern working in other parts of my app but for some reason I have an entity that has some related entities in another table and trying to load them is throwing a null reference exception.\r\n\r\nI'm trying to load them like this:\r\n\r\n``` C#\r\n                var matches = _data.PlayerMatches\r\n                    .Include(pm=>pm.PlayerMatchResults)   <-----  these are the related entities\r\n                    .ToList();\r\n```\r\n\r\nI've got this in my dbcontext class:\r\n\r\n``` C#\r\n            builder.Entity<PlayerMatch>().HasMany(pm=>pm.PlayerMatchResults);\r\n            builder.Entity<PlayerMatchResult>().HasOne(pmr=>pmr.Match);\r\n```\r\n\r\nI'm wondering if it doesn't know what fields/keys should be used to load the related entities.  I've created a FK in the db on the column but it didn't help.  The stack trace doesn't show anything useful.\r\n\r\n```\r\n   at lambda_method(Closure , ValueBuffer )\r\n   at Microsoft.EntityFrameworkCore.Query.EntityLoadInfo.Materialize()\r\n   at Microsoft.EntityFrameworkCore.Query.Internal.QueryBuffer.GetEntity(IKey key, EntityLoadInfo entityLoadInfo, Boolean queryStateManager, Boolean throwOnNullKey)\r\n   at Microsoft.EntityFrameworkCore.Query.Internal.QueryBuffer.<>c__DisplayClass11_0.<Include>b__0(EntityLoadInfo eli)\r\n   at System.Linq.Enumerable.<>c__DisplayClass149_0`3.<CombineSelectors>b__0(TSource x)\r\n   at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()\r\n   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()\r\n   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)\r\n   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)\r\n   at Microsoft.EntityFrameworkCore.Query.Internal.QueryBuffer.Include(QueryContext queryContext, Object entity, IReadOnlyList`1 navigationPath, IReadOnlyList`1 relatedEntitiesLoaders, Int32 currentNavigationIndex, Boolean queryStateManager)\r\n   at Microsoft.EntityFrameworkCore.Query.Internal.QueryBuffer.Include(QueryContext queryContext, Object entity, IReadOnlyList`1 navigationPath, IReadOnlyList`1 relatedEntitiesLoaders, Boolean queryStateManager)\r\n   at Microsoft.EntityFrameworkCore.Query.QueryMethodProvider.<_Include>d__30`1.MoveNext()\r\n   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.<_TrackEntities>d__15`2.MoveNext()\r\n   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()\r\n   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)\r\n   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)\r\n   at LeagueManager.Controllers.DivisionController.ViewMatch(Int32 match_id) in e:\\\\work\\\\personal\\\\LeagueManager\\\\Controllers\\\\DivisionController.cs:line 90\r\n```\r\n\r\nAnyone got any idea what I might be doing wrong?"},"comment":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/comments/255159758","html_url":"https://github.com/aspnet/EntityFramework/issues/6821#issuecomment-255159758","issue_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/6821","id":255159758,"user":{"login":"rykr","id":108892,"avatar_url":"https://avatars.githubusercontent.com/u/108892?v=3","gravatar_id":"","url":"https://api.github.com/users/rykr","html_url":"https://github.com/rykr","followers_url":"https://api.github.com/users/rykr/followers","following_url":"https://api.github.com/users/rykr/following{/other_user}","gists_url":"https://api.github.com/users/rykr/gists{/gist_id}","starred_url":"https://api.github.com/users/rykr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rykr/subscriptions","organizations_url":"https://api.github.com/users/rykr/orgs","repos_url":"https://api.github.com/users/rykr/repos","events_url":"https://api.github.com/users/rykr/events{/privacy}","received_events_url":"https://api.github.com/users/rykr/received_events","type":"User","site_admin":false},"created_at":"2016-10-20T16:38:14Z","updated_at":"2016-10-20T16:38:14Z","body":"Nevermind.  I figured it out.  Stupid user error.  :)"}}
{"actor":{"display_login":"rykr"}}