I am working with EntityFramework and the IRepository Pattern and I need to add some events to all EntityCollections.
Is there a way to get a list of collections on an ObjectContext?
I also need a way to get all the collections on an ObjectSet/EntityCollection. Is that possible?
My end goal here to iterate all collections and sub-collections and add an AssociationChanged Event to all my sub-collections. It will call delete on an object when the relationship is deleted.
This to make up for the fact that EF does not support connectionless deletes (at least not like it supports connectionless Updates and Inserts).
You can get the ObjectSets using the following untested code:
The trick is going to be working with the ObjectSet once you have the instance because it ObjectSet is generic and working with variables of generic types can be less then obvious when you don’t know what type was used to define them.
As for getting the entity collections on an object set, a similar approach can be taken, but I don’t have an example of doing so on hand at the moment.