![](/img/trans.png)
[英]Code First Entity Framework C#, Many to Many Mapping, Junction Table Created but list property not populated on object
[英]C# Entity framework, how to get the primary key from an object created from a Junction table
創建新的APN對象,並通過IPSec交界表添加IPSec對象。 然后,我需要將新的IPSecID(主鍵)添加到BuildType表中。
APN newApn = new APN()
newApn.IPSecs.Add(new IPSec
{
EndPoint = vtcPriEndPoint.Text,
}
newApn.BuildTypes.Add(new BuildType
{
TypeOfBuild = "IPsec",
TransportID = newApn.IPSecID <---no option for this syntax
}
正如你所定義的許多人之間有很多關系APN
和IPSec
,你將不得不for each
通過newApn的IPSecs創造BuildTypes
為他們每個人。
就是說,直到您在上下文中調用SaveChanges
之后,才能知道新IPSecs
的Id
。 或者,您可以將newAPN的每個IPSec
分配給BuildType
的假定Transport
導航屬性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.