2

I can successfully listen to changes on Entity Framework child EntityCollection if the action is add or delete but cannot find the way to listen to changes if the child class property value was updated.

More specifically, in the below, how can I access the property name that was changed on the child ("Employee") class to run some business logic on the parent ("Company") class?

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

I have INotifyPropertyChanged but I don't want to place any code inside employee class to affect the company class directly. Instead I want to catch the change in company class and run the logic there. I'd like to see the Visual Basic example for this.

Nuts
  • 2,755
  • 6
  • 33
  • 78
  • A change of an Employee property is not an association change. (Unless it changes its CompanyId). You _have_ to make `Employee` notify its changes itself. Maybe [this](http://stackoverflow.com/q/4143179/861716) will give you ideas. – Gert Arnold Jun 03 '13 at 09:38
  • I read your link but couldn't quite get the ideas there. So far this http://www.codeproject.com/Articles/36740/Business-Logic-with-Entity-Framework is the closest to my case. They use detail.PropertyChanged += (s, a) => in the AssociationChanged and then condition to find the changed property if (a.PropertyName == "Quantity" || a.PropertyName == "UnitPrice"). I cannot get this to work on VB.Net. Any help appreciated. – Nuts Jun 03 '13 at 10:04

0 Answers0