通过Entity Framework AssociationChanged事件收听属性更改

时间:2013-06-03 08:59:39

标签: entity-framework associations entitycollection

如果操作是添加或删除,我可以成功侦听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的例子。

0 个答案:

没有答案