【发布时间】:2021-04-28 02:08:34
【问题描述】:
我正在尝试设置一个实体框架类,它有 4 个字段链接回相同类型的其他字段或为空。我的班级是这样的:
public class Patch : EntityBase
{
[Key]
public int PatchId { get; set; }
[ForeignKey("NorthPatchId")]
public virtual Patch NorthPatch { get; set; }
[ForeignKey("SouthPatchId")]
public virtual Patch SouthPatch { get; set; }
[ForeignKey("EastPatchId")]
public virtual Patch EastPatch { get; set; }
[ForeignKey("WestPatchId")]
public virtual Patch WestPatch { get; set; }
}
如果我只有 NorthPatch 和 SouthPatch,这可以正常工作,但是当我添加第三个 EastPatch 时,我在尝试进行迁移时收到以下错误:
System.InvalidOperationException: Unable to determine the relationship represented by navigation 'Patch.NorthPatch' of type 'Patch'.
【问题讨论】:
标签: entity-framework-core entity-framework-core-5