Configure multiple relationships between the same types

All relationships with the type must be configured explicitly.

Need to do this if you have more than one relationship with the same type. Examples might include a sporting Fixture, that has a relationship with the Team class both as a HomeTeam and an AwayTeam. Example here is for an EditorialEntry which has relationships denoting the AssignedIssue and the CommissionForIssue, both represented by the Issue type:

HasOptional(p => p.AssignedIssue).WithMany().HasForeignKey(p => p.AssignedIssueId);
HasOptional(p => p.CommissionedForIssue).WithMany().HasForeignKey(p => p.CommissionedForIssueId);

HasOptional becomes HasRequired when the relationship is required.

Last updated: 5/18/2022 10:18:12 AM

Latest Updates

© 0 - 2025 - Mike Brind.
All rights reserved.
Contact me at Mike dot Brind at Outlook.com