我有两个桌子。发票和工厂。
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并未将其映射到正确的键。有想法吗?