开发者

Saving ObservableCollection<> back to sqlite after editing in wpf

I have a master-detail setup showing the items in an ObservableCollection<> that reflects an sqlite table.

It all displays fine, and I can edit the fields that I want with a two-way binding.

But I don't know what the best method is for saving the changes back to the db.

Do I listen for a property change event on my collection and save at that time (every key-press)?

Do I have an event that fires on the editing field losing focus and explicity save that row?

Is there an elegant way to do this? Much of the DB/bindi开发者_运维知识库ng interaction in wpf is pretty easy, but I can't figure this out..


you have to implement Domain Model in your code. Something that dehydrades your sql table representation into C# class and back.

you can use NHibernate or Entity Framework for Object Relational Mapping, so that all persisting into DB or loading it from it is done via ORM.

That way your View doesnt have direct access to DB and it never should. let alone your ViewModel, your ViewModel will only work with DomainModel/BusinessObject and ORM will do the loading/saving bit.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜