gpt4 book ai didi

entity-framework - 不允许多重。 Entity Framework

转载 作者:行者123 更新时间:2023-12-04 08:49:12 26 4
gpt4 key购买 nike

我第一次尝试使用 MVC4 并且在尝试创建 Controller 时收到以下错误?有人可以引导我朝着正确的方向前进吗?

微软视觉工作室

System.Data.Entity.Edm.EdmAssociationEnd: : Multiplicity is not valid in Role 'PropertyData_DNISData_Target' in relationship 'PropertyData_DNISData'. Because the Dependent Role properties are not the key properties, the upper bound of the multiplicity of the Dependent Role must be '*'.


public class PropertyData
{
[Key]
public virtual string PropertyID { get; set; }

[ForeignKey ("DNISData")]
public virtual string DNIS { get; set; }

public virtual string PropertyName { get; set; }
public virtual string PropertyGreeting { get; set; }
public virtual string PropertyOperator { get; set; }
public virtual string InvalidEntryPrompt { get; set; }
public virtual string NoEntryPrompt { get; set; }
public virtual string Comment { get; set; }
public virtual DNISData DNISData { get; set; }

}

public class DNISData
{
[Key]
public virtual string DNIS { get; set; }
[ForeignKey("PropertyData")]
public string PropertyID { get; set; }
public virtual string VDN { get; set; }
public virtual string PropertyGreeting { get; set; }
public virtual string Comment { get; set; }
public virtual PropertyData PropertyData { get; set; }
}

public class DigitData
{
[ForeignKey ("DNISData")]
[Key]
public virtual string DNIS { get; set; }
[Key]
public virtual string Digit { get; set; }
public virtual string InvalidEntryPrompt { get; set; }
public virtual DNISData DNISData { get; set; }
}

最佳答案

您在 PropertyData 和 DNISData 之间存在 1 对 1 的关系。这只能通过 EntityFramework 中的共享主键来完成。

这个问题可以给你你正在寻找的答案:

How to declare one to one relationship using Entity Framework 4 Code First (POCO)

关于entity-framework - 不允许多重。 Entity Framework ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19276381/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com