{"action":"created","issue":{"url":"https://api.github.com/repos/OrchardCMS/Orchard/issues/7278","repository_url":"https://api.github.com/repos/OrchardCMS/Orchard","labels_url":"https://api.github.com/repos/OrchardCMS/Orchard/issues/7278/labels{/name}","comments_url":"https://api.github.com/repos/OrchardCMS/Orchard/issues/7278/comments","events_url":"https://api.github.com/repos/OrchardCMS/Orchard/issues/7278/events","html_url":"https://github.com/OrchardCMS/Orchard/issues/7278","id":182065458,"number":7278,"title":"GetRoles method implementation of IRoleService should not enumerate to concrete collection","user":{"login":"pwdst","id":2559785,"avatar_url":"https://avatars.githubusercontent.com/u/2559785?v=3","gravatar_id":"","url":"https://api.github.com/users/pwdst","html_url":"https://github.com/pwdst","followers_url":"https://api.github.com/users/pwdst/followers","following_url":"https://api.github.com/users/pwdst/following{/other_user}","gists_url":"https://api.github.com/users/pwdst/gists{/gist_id}","starred_url":"https://api.github.com/users/pwdst/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pwdst/subscriptions","organizations_url":"https://api.github.com/users/pwdst/orgs","repos_url":"https://api.github.com/users/pwdst/repos","events_url":"https://api.github.com/users/pwdst/events{/privacy}","received_events_url":"https://api.github.com/users/pwdst/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/OrchardCMS/Orchard/milestones/35","html_url":"https://github.com/OrchardCMS/Orchard/milestones/Orchard%201.10.x","labels_url":"https://api.github.com/repos/OrchardCMS/Orchard/milestones/35/labels","id":1651831,"number":35,"title":"Orchard 1.10.x","description":"","creator":{"login":"sebastienros","id":1165805,"avatar_url":"https://avatars.githubusercontent.com/u/1165805?v=3","gravatar_id":"","url":"https://api.github.com/users/sebastienros","html_url":"https://github.com/sebastienros","followers_url":"https://api.github.com/users/sebastienros/followers","following_url":"https://api.github.com/users/sebastienros/following{/other_user}","gists_url":"https://api.github.com/users/sebastienros/gists{/gist_id}","starred_url":"https://api.github.com/users/sebastienros/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sebastienros/subscriptions","organizations_url":"https://api.github.com/users/sebastienros/orgs","repos_url":"https://api.github.com/users/sebastienros/repos","events_url":"https://api.github.com/users/sebastienros/events{/privacy}","received_events_url":"https://api.github.com/users/sebastienros/received_events","type":"User","site_admin":false},"open_issues":525,"closed_issues":89,"state":"open","created_at":"2016-03-17T17:23:15Z","updated_at":"2016-10-13T19:52:37Z","due_on":"2016-09-01T07:00:00Z","closed_at":null},"comments":3,"created_at":"2016-10-10T17:02:24Z","updated_at":"2016-10-13T19:53:32Z","closed_at":null,"body":"The [GetRoles method of IRoleService](https://github.com/OrchardCMS/Orchard/blob/dev/src/Orchard.Web/Modules/Orchard.Roles/Services/IRoleService.cs) returns a generic IEnumerable collection of type RoleRecord.\r\n\r\n     IEnumerable<RoleRecord> GetRoles();\r\n\r\nThe [implementation of this in RoleService.cs](https://github.com/OrchardCMS/Orchard/blob/dev/src/Orchard.Web/Modules/Orchard.Roles/Services/RoleService.cs#L47) builds an enumerable of this type from a repository, then enumerates this to a collection before returning.\r\n\r\n```\r\npublic IEnumerable<RoleRecord> GetRoles() {\r\n            var roles = from role in _roleRepository.Table select role;\r\n            return roles.ToList();\r\n        }\r\n```\r\n\r\nThis means developers cannot take advantage of SQL filtering or restricting columns as such filtering will be done against the concrete collection in server memory after the entire collection is enumerated. Furthermore this is opaque to the developer as the interface type is an enumerable, not generic ICollection or IList.\r\n\r\nUsing deferred execution would allow developers to write code like -\r\n\r\n     _rolesServices.GetRoles().Where(r => r.Name.Equals(\"Administrator\").Select(r => r.Id);\r\n\r\nThis can then take advantage of SQL optimisations to only query for the data that is actually required, restricting returned columns and using a where predicate."},"comment":{"url":"https://api.github.com/repos/OrchardCMS/Orchard/issues/comments/253620542","html_url":"https://github.com/OrchardCMS/Orchard/issues/7278#issuecomment-253620542","issue_url":"https://api.github.com/repos/OrchardCMS/Orchard/issues/7278","id":253620542,"user":{"login":"sebastienros","id":1165805,"avatar_url":"https://avatars.githubusercontent.com/u/1165805?v=3","gravatar_id":"","url":"https://api.github.com/users/sebastienros","html_url":"https://github.com/sebastienros","followers_url":"https://api.github.com/users/sebastienros/followers","following_url":"https://api.github.com/users/sebastienros/following{/other_user}","gists_url":"https://api.github.com/users/sebastienros/gists{/gist_id}","starred_url":"https://api.github.com/users/sebastienros/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sebastienros/subscriptions","organizations_url":"https://api.github.com/users/sebastienros/orgs","repos_url":"https://api.github.com/users/sebastienros/repos","events_url":"https://api.github.com/users/sebastienros/events{/privacy}","received_events_url":"https://api.github.com/users/sebastienros/received_events","type":"User","site_admin":false},"created_at":"2016-10-13T19:53:31Z","updated_at":"2016-10-13T19:53:31Z","body":"I could understand that users should call `ToList` if they want to prevent multiple enumerations, even if they thought these are not queries."}}
{"actor":{"display_login":"sebastienros"}}