![](/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.