多重不允许的。实体框架 [英] Multiplicity not allowed. Entity Framework

查看:130
本文介绍了多重不允许的。实体框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用MVC4首次和我收到以下错误,当我尝试创建一个控制器?可能有人亲切地引导我朝着正确的方向?


微软的Visual Studio


  

System.Data.Entity.Edm.EdmAssociationEnd:多重性是无效
  在角色的关系PropertyData_DNISData_Target
  PropertyData_DNISData。由于从属角色属性不
  键属性,上部结合的多重的
  相关角色必须是'*'。


 公共类PropertyData
{
    [键]
    公共虚拟字符串物业ID {搞定;组; }    [ForeignKey的(DNISData)]
    公共虚拟字符串DNIS {搞定;组; }    公共虚拟字符串属性名{获得;组; }
    公共虚拟字符串PropertyGreeting {搞定;组; }
    公共虚拟字符串PropertyOperator {搞定;组; }
    公共虚拟字符串InvalidEntryPrompt {搞定;组; }
    公共虚拟字符串NoEntryPrompt {搞定;组; }
    公共虚拟字符串评论{搞定;组; }
    公共虚拟DNISData DNISData {搞定;组; }}公共类DNISData
{
    [键]
    公共虚拟字符串DNIS {搞定;组; }
    [ForeignKey的(PropertyData)]
    公共字符串物业ID {搞定;组; }
    公共虚拟字符串VDN {搞定;组; }
    公共虚拟字符串PropertyGreeting {搞定;组; }
    公共虚拟字符串评论{搞定;组; }
    公共虚拟PropertyData PropertyData {搞定;组; }
}公共类DigitData
{
    [ForeignKey的(DNISData)]
    [键]
    公共虚拟字符串DNIS {搞定;组; }
    [键]
    公共虚拟串数字{搞定;组; }
    公共虚拟字符串InvalidEntryPrompt {搞定;组; }
    公共虚拟DNISData DNISData {搞定;组; }
}


解决方案

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

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

<一个href=\"http://stackoverflow.com/questions/3622572/how-to-declare-one-to-one-relationship-using-entity-framework-4-$c$c-first-poco\">How使用实体框架4 code首先(POCO)申报一对一的关系

I am attempting to use MVC4 for the first time and am receiving the following error when I try to create a controller? Could someone kindly steer me in the right direction?


Microsoft Visual Studio

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; }
}

解决方案

You have a 1 to 1 relationship between PropertyData and DNISData. This can only be done via shared primarykey in EntityFramework.

This question can give you the anwser you are looking for:

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

这篇关于多重不允许的。实体框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆