I am learning ASP.Net MVC 5 and I am stuck with one basic DB Design. So, I have one User which can refer many person in job Also, many person can apply to get themselves Referr
As @SLaks mentioned in the comments, in order to have two relationships, you need two havigation properties (one for each FK).
So in the one side replace Referrals
property with something like this:
public class ApplicationUser : IdentityUser
{
// ...
public ICollection ReferrerOf { get; set; }
public ICollection CandidateOf { get; set; }
}
at many side replace the User
property with:
public class Referral
{
// ...
public ApplicationUser Candidate { get; set; }
public ApplicationUser Referrer { get; set; }
}
and correlate them with fluent API:
modelBuilder.Entity()
.HasMany(u => u.CandidateOf) // <--
.WithRequired(r => r.Candidate) // <--
.HasForeignKey(r => r.CandidateId)
.WillCascadeOnDelete(false);
modelBuilder.Entity()
.HasMany(u => u.ReferrerOf) // <--
.WithRequired(r => r.Referrer) // <--
.HasForeignKey(r => r.ReferrerId);
The names of the navigation properties don't really matter as soon as you correlate them correctly.