2

如果操作是添加或删除,我可以成功收听实体框架子实体集合的更改,但如果子类属性值已更新,我无法找到收听更改的方法。

更具体地说,在下面,我如何访问在子(“员工”)类上更改的属性名称以在父(“公司”)类上运行一些业务逻辑?

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 的例子。

4

0 回答 0