Thank you, Erang, your answer is exactly what I need!
Also, here is the modelBuilder code if someone uses this method instead of the configuration method that Eranga used.
protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<Person>(). HasKey(i => i.PersonId); modelBuilder.Entity<Person>(). HasOptional(f => f.Father). WithMany(f => f.ChildrenAsFather). HasForeignKey(f => f.FatherId); modelBuilder.Entity<Person>(). HasOptional(m => m.Mother). WithMany(m => m.ChildrenAsMother). HasForeignKey(m => m.MotherId); }
source share