我的網(wǎng)站在加載時(shí)崩潰,System.Reflection 中第一次調(diào)用 DbContext 時(shí)出現(xiàn)了一個(gè)非常長(zhǎng)的未處理異常。最后 2 個(gè)字段是相反的[Table("Report_Group")]public class Group{ [Key, Required, Column("GroupId")] public int Id { get; set; } [Required, MaxLength(5)] public string OrgCode { get; set; } [Required, MaxLength(100)] public string Name { get; set; } public int TierId { get; set; } public int? ParentGroupId { get; set; } public int? CostCenter { get; set; } [Required] public int ExcludeFromAlertStats { get; set; } [Required] public int GroupTypeId { get; set; } [ForeignKey("ParentGroupId")] public virtual Group Parent { get; set; } [ForeignKey("OrgCode")] public virtual Organisation Organisation { get; set; } [ForeignKey("TierId")] public virtual Tier Tier { get; set; } [ForeignKey("GroupTypeId")] public virtual GroupType GroupType { get; set; } [InverseProperty("GroupId")] public virtual IList<GroupToUnitLink> UnitLinks { get; set; } [InverseProperty("GroupId")] public virtual IList<GroupToContactLink> ContactLinks { get; set; }}
2 回答

MMTTMM
TA貢獻(xiàn)1869條經(jīng)驗(yàn) 獲得超4個(gè)贊
您的問(wèn)題是 inverse 屬性不是 GroupToContactLink 類上引用 Contact 類的字段。
[InverseProperty("ContactId")] // Wrong: don't use the field
但引用 Contact 類的是 GroupToContactLink 類上的導(dǎo)航屬性。
[InverseProperty("Contact")] // Correct: use the navigation property
- 2 回答
- 0 關(guān)注
- 175 瀏覽
添加回答
舉報(bào)
0/150
提交
取消