将表中不存在的字段映射为复合外键EF6之一

时间:2019-03-05 13:54:14

标签: c# entity-framework-6 foreign-keys data-annotations composite-primary-key

我有两个桌子。发票和工厂。

 public partial class Invoice
{  
    [Key]
    public int InvoiceId{ get; set;}
    [Foreignkey("Site"] 
    public int SiteId{ get; set; }

    //There is no field in this table that gives me the corporateId    

    [InverseProperty("Invoices")]
    public Site Site{ get; set; }

}

     public partial class Sites
{  
    [Column(Order = 0)]
    [Key]
    public int SiteId{ get; set;}
    [Column(Order = 1)]  
    [Key] 
    public int CorporateId{ get; set; }

    [InverseProperty("Site")]
    public ICollection<Invoices> Invoices{ get; set; }

}

我想使用Context.Invoices.Include(s => s.Site)代替联接。我知道我需要哪个CorportageId。我想为每张发票设置相同。我尝试在“发票”中添加一个字段,但EF并未将其映射到正确的键。有想法吗?

0 个答案:

没有答案
相关问题