Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 尝试定义1:1关系时出现多重性无效错误_C#_Asp.net_Entity Framework_Database Design_Foreign Keys - Fatal编程技术网

C# 尝试定义1:1关系时出现多重性无效错误

C# 尝试定义1:1关系时出现多重性无效错误,c#,asp.net,entity-framework,database-design,foreign-keys,C#,Asp.net,Entity Framework,Database Design,Foreign Keys,所以我有一个场景(在ASP.NETMVC中)要求我有四个表。其中三个表需要与第一个表具有1:1的关系。当我尝试运行code first迁移来定义这一点时,会出现以下错误: One or more validation errors were detected during model generation: ANA_ANASection2_Target: : Multiplicity is not valid in Role 'ANA_ANASection2_Target' in relati

所以我有一个场景(在ASP.NETMVC中)要求我有四个表。其中三个表需要与第一个表具有1:1的关系。当我尝试运行code first迁移来定义这一点时,会出现以下错误:

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 '*'.
如何正确激活这些关系?我不介意丢失数据,因为我们仍在开发中

我的模式如下(我将尝试简化它):


您只需要在ANA中将字段标记为虚拟字段。除此之外,您使用的是3个相同的类,为什么不在表中添加一个节ID并将其减少为1?我已经极大地简化了类,它们实际上都有与问题无关的非常不同的字段。试图将其标记为虚拟,但不起作用。
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; }
}