ef6将父表中的第一个标识密钥作为子表中的外键

时间:2016-03-20 04:41:22

标签: c# database entity-framework data-annotations

我在下面给出了我的实体的描述。它将更容易理解

家长实体

    [Key]
    [Column(Order = 0)]
    [Required]
    public virtual string Invno { get; set; }

     [Key]
    [Column(Order =1)]
    [Required]
    public virtual string Customer { get; set; }


    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public virtual int Sslno { get; set; }


    public virtual ICollection<ChildEntity> ChildEntity { get; set; }

儿童实体

    [Key]
    [Column(Order = 0)]
    [Required]
    public virtual string Itemcode { get; set; }


    [Key]
    [Column(Order = 1)]
    [Required]
    public virtual double Price { get; set; }


    [Key]
    [Column(Order = 2)]
    [Required]
    public virtual int Sslno { get; set; }


    [ForeignKey("Sslno")]
    public virtual ParentEntity ParentEntity { get; set; }

给我错误:

  

关系约束中的从属角色和主要角色中的属性数必须相同

注意:我不想让Invno和客户成为外键

0 个答案:

没有答案
相关问题