开发者

Persisting of ObservableCollection<T> to DataStore

开发者 https://www.devze.com 2023-02-19 01:32 出处:网络
I have an ObservableCollection<T> (T being a set of entities loaded using OData)开发者_JAVA百科 which is correctly maintaining updates to its contents.The collection is displayed in a DataGrid a

I have an ObservableCollection<T> (T being a set of entities loaded using OData)开发者_JAVA百科 which is correctly maintaining updates to its contents. The collection is displayed in a DataGrid and the user clicks a button in order to save the collection back to a database.

Is there any way that I can test the collection for updated items, limiting the number of writes required to those entities that have actually been updated.


If you use the .NET Entity Framework for interacting with the database, it will do a lot of this for you.

But if you want to do it from scratch the easiest way is to implement INotifyPropertyChanged on each item in the collection. When soemthing is added to the collection, add a listener to it's PropertyChanged event. Now you can get notified of and keep track of all changes.

0

精彩评论

暂无评论...
验证码 换一张
取 消