This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
We are utilizing the EntityAdded / Removed events on an EntityCollection in certain cases to subscribe to PropertyChanged event notifications for elements in the collection. In this way we conveniently bubbling up property changed notifications from deep within an object graph so that our domain model can then richly fire appropriate events. We have bundled this functionality up in a derivation of the EntityCollection and are using it. The problem we are encountering is that when entities are re-hydrated, the EntityCollection doesn't seem to fire EntityAdded / Removed events and thus we never get an opportunity to subscribe to the PropertyChanged event on each collection element. I presume this is for perf reasons. We have attempted to wire them up in a batch using reflection within the Entity AfterLoad member, but then discovered that this fires before the EntityCollections on that entity have been populated. We need a hook to wire up to the property change events of the collection elements. If the EntityCollection had an AfterLoad equivalent this would fit the bill and preserve performance. How feasible is it to implement this? I think my only other alternative is to manually take care of this for every entity type or do some really messy reflection after a collection element is loaded. |
|
|
I think we could do that, but if you are deriving from EntityCollection already, a quicker fix might be to override InsertItem. The implementation would call the base implementation and then raise a custom event (or even perform the hookup itself if appropriate). This does have the downside that it is called for every add, so there would be a danger of being notified twice for items added after loading is complete (once for InsertItem and once for the EntityAdded event), but I guess you could centralise everything in your InsertItem override and skip the event altogether (and probably do the same for RemoveItem / EntityRemoved for symmetry). Is that a viable solution for you? |
|
|
Ok thanks Ivan, I have an update on this that may be even better. As an experiment i overrode InsertItem and noticed that it is getting called 2X for every insert into the collection. It appears that the polymorphic InsertItem is getting called from EntityCollection causing two invocations of an InsertItem override. I'm not sure if this is intentional from Mindscape's perspective, it certainly doesn't seem good. You guys might want to investigate this. The best solution to the problem I was trying to solve seemed to already be baked in though through the EntityCollection's implementation of BindingList. The EntityCollection implements the IRaiseItemChangedEvents interface, which, when queried indicates whether the collection instance does indeed raise events when properties on elements of the collection are changed. EntityCollection returned true for this, so I can safely use IBindingList.ListChanged to see the property changes that we're interested in without any custom extension of EntityCollection. Hope this helps somebody else |
|