1

Is there any way to see how the relationships of an Entity were affected/changed inside of a ChangeInterceptor()? Here is an example using NorthWind Database, when you delete/remove an Order Entity from an Employee Entity where the relationship is one-to-many, one Employee has many Orders, how can detect an Order was removed from the Employee Entity. I know using the ObjectStateEntry class you can call GetModifiedProperties() to see what Properties changed, but how do we see what Collections/Associations changed?. Does it have something to do with the RelationshipManager?

[ChangeInterceptor("Employees"]
public void OnChangeEmployees(Employee employee, UpdateOperations operations)
{
    //I'm using EntityFramework 4.1
    //We have to dropdown the ObjectContext to detect IA, Independant Association, changes
    ObjectContext ctx = ((IObjectContextAdapter)this.CurrentDataSource).ObjectContext;

    ObjectStateEntry entry = ctx.ObjectStateManager.GetObjectStateEntry(employee);

    //What do I do here for detecting relationship changes.. I.E and Order was added?


} 

Thanks in advance.

1 Answer 1

0

Instead of using a ChangeInterceptor... Just implement the SavingChanges event handler on the ObjectContext. This article explains how to see if an Entity's relationship was affected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.