{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/3241","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/3241/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/3241/comments","events_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/3241/events","html_url":"https://github.com/aspnet/EntityFramework/issues/3241","id":108496889,"number":3241,"title":"Support for querying a hierarchy of self-referencing entities?","user":{"login":"weitzhandler","id":2716316,"avatar_url":"https://avatars.githubusercontent.com/u/2716316?v=3","gravatar_id":"","url":"https://api.github.com/users/weitzhandler","html_url":"https://github.com/weitzhandler","followers_url":"https://api.github.com/users/weitzhandler/followers","following_url":"https://api.github.com/users/weitzhandler/following{/other_user}","gists_url":"https://api.github.com/users/weitzhandler/gists{/gist_id}","starred_url":"https://api.github.com/users/weitzhandler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/weitzhandler/subscriptions","organizations_url":"https://api.github.com/users/weitzhandler/orgs","repos_url":"https://api.github.com/users/weitzhandler/repos","events_url":"https://api.github.com/users/weitzhandler/events{/privacy}","received_events_url":"https://api.github.com/users/weitzhandler/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-09-26T21:28:14Z","updated_at":"2015-10-16T02:32:48Z","closed_at":"2015-09-28T17:46:34Z","body":"Hi,\r\n\r\nOften you need to retrieve a whole hierarchy of self-referencing entities.\r\n\r\nConsider this example:\r\n\r\n    public class Affiliate\r\n    {\r\n      public int Id { get; set; }\r\n      public string Name { get; set; }\r\n      //The person who referred the current one\r\n      public in ReferrerId { get; set; }\r\n      [ForeignKey(nameof(ReferrerId)]\r\n      public Affiliate Referrer { get; set; }\r\n      //People the current has referred\r\n      public virtual ICollection<Affiliate> Referred { get; set; } = new HashSet<Affiliate>();\r\n    }\r\n\r\nNow I want to retrieve an `Affiliate` along with its children, grandchildren, and great grandchildren. Or I want to retrieve an `Affiliate` with its `Referrer`, he's referrer's referrer, and his referrer's referrer's referrer `n` levels up.\r\n\r\nHow can this be achieved in a single round-trip without involving stored-procedures?\r\n\r\n - Can Linq Expressions be used for this?\r\n - Is there a repo for that?\r\n - Anything for EF6?"},"comment":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/comments/148580490","html_url":"https://github.com/aspnet/EntityFramework/issues/3241#issuecomment-148580490","issue_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/3241","id":148580490,"user":{"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},"created_at":"2015-10-16T02:32:48Z","updated_at":"2015-10-16T02:32:48Z","body":"@weitzhandler yes, ThenInclude if EF7 API, mainly to allow chaining includes on collections in a strongly typed fashion. "}}