Estoy utilizando la base de datos EntityFramework primero en una aplicación. Me gustaría de alguna manera ser notificado de los cambios a un EntityCollection
en mi ViewModel. No es compatible directamente con INotifyCollectionChanged
(¿por qué?) Y no he tenido éxito en encontrar otra solución.EntityFramework EntityCollection Observando CollectionChanged
Aquí es mi último intento, que no funciona porque el evento ListChanged
no parece quedar levantado:
public class EntityCollectionObserver<T> : ObservableCollection<T>, INotifyCollectionChanged where T : class
{
public event NotifyCollectionChangedEventHandler CollectionChanged;
public EntityCollectionObserver(EntityCollection<T> entityCollection)
: base(entityCollection)
{
IBindingList l = ((IBindingList)((IListSource)entityCollection).GetList());
l.ListChanged += new ListChangedEventHandler(OnInnerListChanged);
}
private void OnInnerListChanged(object sender, ListChangedEventArgs e)
{
if (CollectionChanged != null)
CollectionChanged(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
}
}
¿Alguien tiene alguna idea de cómo podría observar cambios en un EntityCollection
?
Dan
También vea http://stackoverflow.com/questions/6264979/changing-association-property-entitycollection-dont-rise-propertychanged – OneWorld