当涉及到单个对象的外键时,我们会有一个属性:
SingleMap.cs
[ForeignKey("ApplicationUser")]
public int ApplicationUserID { get; set; }
public ApplicationUser ApplicationUser { get; set; }
当我们有一个ApplicationUsers列表时,我们如何映射外键?
ManyMap.cs
public ICollection<ApplicationUser> ApplicationUserList { get; set; }
它通常是这样使用的:
public class ManyMap
{
public int ID {get; set;}
.....
[InverseProperty(nameof(ApplicatonUser.ManyMap))]
public ICollection<ApplicationUser> ApplicationUsers{ get; set; }
}
public class ApplicationUser
{
......
public int ManyMapID { get; set; }
[ForeignKey(nameof(ManyMapID))]
[InverseProperty("ApplicationUsers")]
public ManyMap ManyMap { get; set; }
}