如果操作是添加或删除,我可以成功侦听Entity Framework子EntityCollection上的更改,但如果子类属性值已更新,则无法找到侦听更改的方法。
更具体地说,在下面,我如何访问在子(“Employee”)类上更改的属性名称以在父(“Company”)类上运行某些业务逻辑?
Public Sub New()
AddHandler Me.employees.AssociationChanged, AddressOf employees_AssociationChanged
End Sub
Private Sub employees_AssociationChanged(ByVal sender As Object, ByVal e As CollectionChangeEventArgs)
Dim act As CollectionChangeAction = e.Action
Dim employeeOnOtherEnd As employee = CType(e.Element, employee)
If Not employeeOnOtherEnd Is Nothing Then
If act = CollectionChangeAction.Add Then
'logic when new employee added
ElseIf act = CollectionChangeAction.Remove Then
'logic when new employee was deleted
End If
'I want to run some business logic here if some employee property value was updated... How to do that?
End If
End Sub
我有INotifyPropertyChanged,但我不想在员工类中放置任何代码直接影响公司类。相反,我想抓住公司类的变化并在那里运行逻辑。我想看看Visual Basic的例子。