{"action":"created","issue":{"url":"https://api.github.com/repos/json-api-dotnet/JsonApiDotNetCore/issues/381","repository_url":"https://api.github.com/repos/json-api-dotnet/JsonApiDotNetCore","labels_url":"https://api.github.com/repos/json-api-dotnet/JsonApiDotNetCore/issues/381/labels{/name}","comments_url":"https://api.github.com/repos/json-api-dotnet/JsonApiDotNetCore/issues/381/comments","events_url":"https://api.github.com/repos/json-api-dotnet/JsonApiDotNetCore/issues/381/events","html_url":"https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/381","id":351661753,"node_id":"MDU6SXNzdWUzNTE2NjE3NTM=","number":381,"title":"Potential Include Bug","user":{"login":"RKennedy9064","id":7996786,"node_id":"MDQ6VXNlcjc5OTY3ODY=","avatar_url":"https://avatars1.githubusercontent.com/u/7996786?v=4","gravatar_id":"","url":"https://api.github.com/users/RKennedy9064","html_url":"https://github.com/RKennedy9064","followers_url":"https://api.github.com/users/RKennedy9064/followers","following_url":"https://api.github.com/users/RKennedy9064/following{/other_user}","gists_url":"https://api.github.com/users/RKennedy9064/gists{/gist_id}","starred_url":"https://api.github.com/users/RKennedy9064/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RKennedy9064/subscriptions","organizations_url":"https://api.github.com/users/RKennedy9064/orgs","repos_url":"https://api.github.com/users/RKennedy9064/repos","events_url":"https://api.github.com/users/RKennedy9064/events{/privacy}","received_events_url":"https://api.github.com/users/RKennedy9064/received_events","type":"User","site_admin":false},"labels":[{"id":890392183,"node_id":"MDU6TGFiZWw4OTAzOTIxODM=","url":"https://api.github.com/repos/json-api-dotnet/JsonApiDotNetCore/labels/needs-investigation","name":"needs-investigation","color":"fef2c0","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-08-17T16:37:33Z","updated_at":"2018-08-20T21:39:01Z","closed_at":null,"author_association":"NONE","body":"## Description\r\n\r\nI've been working on a workaround for sorting using nested relationships and have run into something weird. I've added an attribute on my model to expose the nested attribute like so.\r\n\r\n```c#\r\n[NotMapped]\r\n[Attr(\"staff-roster-last-name\")]\r\npublic string StaffRosterLastName => \r\n  StaffRoster != null ? StaffRoster.LastName : String.Empty;\r\n```\r\n\r\nI'm able to access the attribute and display it on the front end, but when I try to sort by staff-roster-first-name, StaffRoster is always null when the sort filters are applied. The weird thing that I've noticed during various tests is that if I add a call ToList on the entities inside of EntityResourceService.cs GetAsync(), StaffRoster becomes available and the sorting works correctly. I know calling ToList executes the query, I'm just not sure why the included model isn't available unless I add the line of code. My url looks like this.\r\n\r\n```\r\nhttp://localtest.me:5000/api/v1/sample-units?include=field-disposition%2Csample-disposition%2Cstaff-roster&page%5Bnumber%5D=1&page%5Bsize%5D=25&sort=staff-roster-last-name\r\n```\r\n\r\nAnd the code I'm referring to looks like so.\r\n\r\n```c#\r\npublic virtual async Task<IEnumerable<TResource>> GetAsync()\r\n{\r\n  var entities = _entities.Get();\r\n\r\n  entities = ApplySortAndFilterQuery(entities);\r\n\r\n  if (ShouldIncludeRelationships())\r\n    entities = IncludeRelationships(entities, _jsonApiContext.QuerySet.IncludedRelationships);\r\n\r\n  if (_jsonApiContext.Options.IncludeTotalRecordCount)\r\n    _jsonApiContext.PageManager.TotalRecords = await _entities.CountAsync(entities);\r\n\r\n  // This is the line I added.\r\n  entities.ToList();\r\n\r\n  // pagination should be done last since it will execute the query\r\n  var pagedEntities = await ApplyPageQueryAsync(entities);\r\n  return pagedEntities;\r\n}\r\n```\r\n\r\nFor some reason the only way I can get StaffRoster to not be null and sort correctly is if I explicitly call entities.ToList() before ApplyPageQueryAsync is called. Looking through the paging code it looks like eventually ToListAsync() is called. so I'm not sure why an extra call of ToList is needed for the sort to work correctly. Do you have any idea why this might be the case? Any input would be greatly appreciated.\r\n\r\n## Environment\r\n\r\n- JsonApiDotNetCore Version: Master branch as of 8/17/2018\r\n- Other Relevant Package Versions: N/A"},"comment":{"url":"https://api.github.com/repos/json-api-dotnet/JsonApiDotNetCore/issues/comments/414472118","html_url":"https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/381#issuecomment-414472118","issue_url":"https://api.github.com/repos/json-api-dotnet/JsonApiDotNetCore/issues/381","id":414472118,"node_id":"MDEyOklzc3VlQ29tbWVudDQxNDQ3MjExOA==","user":{"login":"RKennedy9064","id":7996786,"node_id":"MDQ6VXNlcjc5OTY3ODY=","avatar_url":"https://avatars1.githubusercontent.com/u/7996786?v=4","gravatar_id":"","url":"https://api.github.com/users/RKennedy9064","html_url":"https://github.com/RKennedy9064","followers_url":"https://api.github.com/users/RKennedy9064/followers","following_url":"https://api.github.com/users/RKennedy9064/following{/other_user}","gists_url":"https://api.github.com/users/RKennedy9064/gists{/gist_id}","starred_url":"https://api.github.com/users/RKennedy9064/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RKennedy9064/subscriptions","organizations_url":"https://api.github.com/users/RKennedy9064/orgs","repos_url":"https://api.github.com/users/RKennedy9064/repos","events_url":"https://api.github.com/users/RKennedy9064/events{/privacy}","received_events_url":"https://api.github.com/users/RKennedy9064/received_events","type":"User","site_admin":false},"created_at":"2018-08-20T21:39:01Z","updated_at":"2018-08-20T21:39:01Z","author_association":"NONE","body":"Yeah I'm a little confused as to why it worked after materializing also, especially since it was materialized after the sort had been applied. I'll just override the ApplySortAndFilterQuery to handle the specific cases I need. Thanks for the help."}}
{"actor":{"display_login":"RKennedy9064"}}