在 AssociationAttribute、Linq 中反映通过触发器创建的记录时出现问题
表As和Bs之间存在一对n关系(外键关系)。每次在 As 中添加新记录时,表 As 中的“更新后”触发器都会在表 Bs 中创建 n 条记录。
有两个 Linq-to-SQL 类 A 和 B 分别代表表 As 和 Bs。
类 A 包含 B 属性(B 的 EntitySet)。类似地,在类 B 中,有一个属性 A,一个 EntityRef(of A)
查看以下代码:
Public Function NewRecsOfB() As Integer
Dim objDCDC As New DataClassesDataContext(gstrDatabaseValues)
'gstrdatabaseValues contains the connection string
Dim objA As New A
objDCDC.As.InsertOnSubmit(objA)
objDCDC.SubmitChanges()
NewRecsOfB = objA.Bs.count
objDCDC.Connection.Close()
objDCDC = Nothing
End Function
执行上述函数时,结果始终为 0。而每次执行上述操作时,都会向表 Bs 添加 6 条新记录函数被执行。
请帮助解决上述问题。谢谢。
There is one-to-n relationship (foreign-key relationship) between tables As and Bs. Every time a new record is added in As, a trigger "after update" in table As creates n records in table Bs.
There are two Linq-to-SQL classes A and B representing the tables As and Bs respectively.
The class A contains Bs property an EntitySet(of B). Similarly in class B, there is a property A, an EntityRef(of A)
Look into following code:
Public Function NewRecsOfB() As Integer
Dim objDCDC As New DataClassesDataContext(gstrDatabaseValues)
'gstrdatabaseValues contains the connection string
Dim objA As New A
objDCDC.As.InsertOnSubmit(objA)
objDCDC.SubmitChanges()
NewRecsOfB = objA.Bs.count
objDCDC.Connection.Close()
objDCDC = Nothing
End Function
When above function is executed the result is always 0. Whereas there are six records new records has been added to table Bs every time the above function is executed.
Please help in resolving the above problem. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定这是否是最好的方法,但您可以
Dispose()
数据上下文,创建新的数据上下文,通过 id 获取objA
的新副本并检索Bs
。I'm not sure if this is the best way, but you can
Dispose()
of your data context, create new one, get new copy ofobjA
by id and retrieveBs
from that.