我有一个处理程序,当对其中一个实体对象进行更新时会导致执行子context_SaviningChanges:
AddHandler Me.SavingChanges, AddressOf context_SavingChanges
我希望为正在更新的每个实体执行特定代码。所以,如果它是一个“电话”实体,我想触发一段代码,但如果它是一个“建筑物”实体,我想触发另一段代码。在伪代码中我想做这样的事情:
For Each entry as ObjectStateEntry in DirectCast(sender, ObjectContext).ObjectStateManager.GetObjectStateEntries(EntityState.Modified)
If entry.entity("phone") Then
... code goes here for phone changes ...
ElseIf entry.entity("building")
... code goes here for building changes ...
Else
... code goes here for other entity changes ...
Next
答案 0 :(得分:3)
您可以检查ObjectStateEntry.Entity [msdn]的类型:
If TypeOf entry.Entity Is Phone Then
' ...
End If