你可以申请 ForeignKey 导航属性的属性使用逗号分隔的字符串和属性名称:
ForeignKey
public class This_One { [Key, Column(Order = 1)] public int CommonColumn { get; set; } [Key, Column(Order = 2)] public int ColumnOne { get; set; } [Key, Column(Order = 3)] public int ColumnTwo { get; set; } [ForeignKey("CommonColumn,ColumnOne")] public Other_One Other_One { get; set; } [ForeignKey("CommonColumn,ColumnTwo")] public Other_Two Other_Two { get; set; } }
摘录自 ForeignKey 构造函数 文件 :
如果将ForeigKey属性添加到外键属性,则应指定关联导航属性的名称。如果将ForeigKey属性添加到导航属性,则应指定关联外键的名称。 的 如果导航属性具有多个外键,请使用逗号分隔外键名称列表。 强>