我正在学习ASP。Net MVC 5和我一直坚持一个基本的数据库设计。
送交
推荐模式:
Public class Referral
{
[Key]
public int ReferralId { get; set; }
public Company Company { get; set; }
public int CompanyId { get; set; }
public ApplicationUser User { get; set; }
public string CandidateId { get; set; } // Application User ID of person asking for referral
public string ReferrerId { get; set; } // Application user ID of person referring the candidate
}
应用程序用户模型
public class ApplicationUser : IdentityUser
{
public ICollection<Referral> Referrals { get; set; }
// rest prop removed for brevity sake
}
现在,假设A(推荐人)引用B(候选人)。我的桌子行如下所示。
ReferralId CompanyId CandidateId ReferrerId
1 1 B A
到目前为止,一切都很好。但我想在转诊表上建立FK关系。我不熟悉Fluent API,但我试过如下方法。
// one candidate can have many referrals
dBModelBuilder.Entity<ApplicationUser>()
.HasMany(u => u.Referrals)
.WithRequired(u => u.User)
.HasForeignKey(u => u.CandidateId)
.WillCascadeOnDelete(false);
//one referrar can have many referrals
dBModelBuilder.Entity<ApplicationUser>()
.HasMany(u => u.Referrals)
.WithRequired(u => u.User)
.HasForeignKey(u => u.ReferrerId);
预期行为:我预期有两个FK的关系。一旦我有了它,我就可以相应地工作了。请引导我到这里。我对这一切都不熟悉。