Closed as not planned
Description
Hi,
Often you need to retrieve a whole hierarchy of self-referencing entities.
Consider this example:
public class Affiliate
{
public int Id { get; set; }
public string Name { get; set; }
//The person who referred the current one
public in ReferrerId { get; set; }
[ForeignKey(nameof(ReferrerId)]
public Affiliate Referrer { get; set; }
//People the current has referred
public virtual ICollection<Affiliate> Referred { get; set; } = new HashSet<Affiliate>();
}
Now 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.
How can this be achieved in a single round-trip without involving stored-procedures?
- Can Linq Expressions be used for this?
- Is there a repo for that?
- Anything for EF6?
Metadata
Metadata
Assignees
Labels
No labels