One to many recursive relationship with Code First
问题 I am trying to implement a simple self referencing relationship with EF 6.1.2 Code First. public class Branch { [Key] public int Id { get; set; } [Required] public string Name { get; set; } public int? ParentId { get; set; } [ForeignKey("ParentId")] public virtual Branch Parent { get; set; } public ICollection<Branch> Children { get; set; } // direct successors } In my application I have exactly one root branch. And except for this single root branch, every branch has exactly one parent (the