How do I detect that a Collection Has Changed within an entity ON SavingChanges?
I am implementing OnSaveChanges() when saving an entity.
Apart from finding out all the properties of the entity that have changed how do I find out all the properties of a collection within the entity that have changed?
EG Customer has a property
public List<Address>AddressList {get;set;}
Now if one of those addresses changes how do I detect it?
I am using the following to detect all the ObjectStateEntry modified
IEnumerable<Object开发者_C百科StateEntry> changes =
stateManager.GetObjectStateEntries(EntityState.Added | EntityState.Modified | EntityState.Deleted);
now as a said apart from the changes to the entity I need to find all the changes to the collections the entity might have.
How do you do it?
You will need to call ObjectContext.DetectChanges() prior to calling SaveChanges(). If you don't do this, the items in the collections will not be included in GetObjectStateEntries at the time of your SavingChanges method being called.
精彩评论