本文介绍了无法确定关系的原则结束 - 多个添加的实体可能具有相同的主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
套有卡和套。这是我在我的模型中使用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:
任何想法为什么?
推荐答案
对于在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
这篇关于无法确定关系的原则结束 - 多个添加的实体可能具有相同的主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!