Reputation: 151
Pretty straightforward question... What is the most common way for programmers to synchronise the changes in an observable collection with their object context (EF4)? In my situation I have a sql ce 4.0 db using EF4 as my ORM, and I am working with an observable collection that takes objects from the database (MVVM).
Basically I want to know the most logical way to setup some code that adds, removes, modifies the object context when I am manipulating the observable collection.
Cheers
Upvotes: 0
Views: 518
Reputation: 19857
You can subscribe to the CollectionChanged event of the ObservableCollection, and add in any EF logic to save inserts/deletions to your database model.
Upvotes: 1
Reputation: 20471
The simplest way to achieve this is to create your own custom collection class that implements INotifyCollectionChanged
. By doing this you have an opportunity to add and delete entities when the collection changes. Updating entities would not be the role of the collection class, but more a function of a model wrapper or viewmodel for each entity.
Upvotes: 0