簡體   English   中英

C#實體框架,如何從通過Junction表創建的對象中獲取主鍵

[英]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
                     }

正如你所定義的許多人之間有很多關系APNIPSec ,你將不得不for each通過newApn的IPSecs創造BuildTypes為他們每個人。

就是說,直到您在上下文中調用SaveChanges之后,才能知道新IPSecsId 或者,您可以將newAPN的每個IPSec分配給BuildType的假定Transport導航屬性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM