在可选的下一个和上一个对象ID中,从属角色必须为“ *”

时间:2019-07-18 17:46:57

标签: database entity-framework entity-framework-6 foreign-keys data-annotations

我的应用程序要求在编辑后将估算成本创建为新的,因此我需要在旧估算成本中输入新创建的估算成本的ID和新估算成本中的旧估算成本的ID。这些值是可选的(估计的成本永远不会被任何人编辑)。尝试添加迁移时,我得到

  

PotentialEstimatedCost_PreviousVersion_Target::多重性不是   在角色“ PotentialEstimatedCost_PreviousVersion_Target”中有效   关系“ PotentialEstimatedCost_PreviousVersion”。因为   从属角色属性不是关键属性,上限   从属角色的多重性必须为“ *”。错误。

如何解决这个问题?

public partial class PotentialEstimatedCost
    {
        [Key]
        public int ID { get; set; }

        public bool Active { get; private set; }

        public bool IsInBuffer { get; private set; }

        public DateTime Date { get; private set; }

        public string Name { get; private set; }

        public string Notes { get; private set; }

        [ForeignKey("PreviousVersion")]
        public int? PreviousVersionID { get; set; }
        public virtual PotentialEstimatedCost PreviousVersion { get; set; }

        [ForeignKey("NextVersion")]
        public int? NextVersionID { get; set; }
        public virtual PotentialEstimatedCost NextVersion { get; set; }
    }

0 个答案:

没有答案