无法确定关系的原则结束 - 多个添加的实体可能具有相同的主键

无法确定关系的原则结束 - 多个添加的实体可能具有相同的主键

问题描述:

套有卡和套。这是我在我的模型中使用EF代码第一:

Sets have Cards and Sets. Here's what I have in my model, using EF Code First:

public class Set
{
    // Primitive Properties 
    [Required]
    [Key]
    public virtual int SetId { get; set; }

    // Navigation Properties 
    [Required]
    public virtual List<Set> Sets { get; set; }

    // Navigation Properties
    [ForeignKey("ParentSet")]
    public int ParentSetId { get; set; }
    public virtual Set ParentSet { get; set; }
}

然后为卡片:

public class Card
{
    // Primitive Properties
    [Required]
    [Key]
    public virtual int CardId { get; set; }

    // Navigation Properties
    [Required]
    [ForeignKey("ParentSet")]
    public int ParentSetId { get; set; }
    public virtual Set ParentSet { get; set; }
}

我正在尝试使用'update-database'从包管理器控制台,这是我得到的错误:

I'm trying to rebuild the database using 'update-database' from the package manager console and this is the error I'm getting:


无法确定
'应用程序的主体端.Core.Set_ParentSet'关系。多个添加的实体
可能具有相同的主键。

Unable to determine the principal end of the 'App.Core.Set_ParentSet' relationship. Multiple added entities may have the same primary key.

任何想法为什么?

对于在Set实体中拥有这一点,我没有意义。它不能引用自己并被要求

To me having this in the Set entity doesn't make sense. It can't refer to itself and be required

// Navigation Properties 
[Required]
public virtual List<Set> Sets { get; set; }

如果一个 Set 有一个列表设置,你如何创建第一个 Set

If a Set HAS to have a list of Sets, how can you create the first Set?

请注意,从错误中写出的内容与卡类无关。

Note that from what's written in the error, it has nothing to do with the Card class