所以我有一个场景(在ASP.NET MVC中)要求我有四个表。其中三个需要与第一个表具有1:1的关系。当我尝试运行代码首次迁移来定义它时,我得到了这些错误:
One or more validation errors were detected during model generation:
ANA_ANASection2_Target: : Multiplicity is not valid in Role 'ANA_ANASection2_Target' in relationship 'ANA_ANASection2'. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be '*'.
ANA_ANASection3_Target: : Multiplicity is not valid in Role 'ANA_ANASection3_Target' in relationship 'ANA_ANASection3'. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be '*'.
ANA_ANASection4_Target: : Multiplicity is not valid in Role 'ANA_ANASection4_Target' in relationship 'ANA_ANASection4'. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be '*'.
如何正确激活这些关系?我不介意丢失数据,因为我们仍在开发中。
我的架构如下(我会尝试简化它):
public class ANASection2
{
[Key]
public int ANASection2Id { get; set; }
[ForeignKey("ANA")]
public int ANAId { get; set; }
[Required]
public virtual ANA ANA { get; set; }
}
public class ANASection3
{
[Key]
public int ANASection3Id { get; set; }
[ForeignKey("ANA")]
public int ANAId { get; set; }
[Required]
public virtual ANA ANA { get; set; }
}
public class ANASection4
{
[Key]
public int ANASection4Id { get; set; }
[ForeignKey("ANA")]
public int ANAId { get; set; }
[Required]
public virtual ANA ANA { get; set; }
}
public class ANA
{
public int ANAId { get; set; }
[Required]
public ANASection2 ANASection2 { get; set; }
[Required]
public ANASection3 ANASection3 { get; set; }
[Required]
public ANASection4 ANASection4 { get; set; }
}