Entity framework architecture for WPF MVVM applications

a 夏天 提交于 2019-12-11 05:54:56

问题


I'm currently developing an WPF application sticking to the MVVM-pattern.

On the persistence side I'm using the Entity Framework (Code first) with repositories and UnitOfWork:

The implementation is described here.

I had a lot of good experiences with this architecture in web-context (asp.net MVC). Unfortunately using this architecture on desktop applications doesn't seem to be appropriate. I have some trouble:

I'm loading my database model with the Unit Of Work- and Repository-pattern. It's assigned to a variable in my ViewModel. The public properties of my ViewModel reference to the variables of my database model. There is the first problem: When a user now changes a properties content via the view, the change is made to the database model as well. When the view is now closed (without "saving") and opened again later on, the changes are still there. For this reason I always create "copies" of my database model objects when they are loaded. This leads not only to a lot of code which I would like to get rid of but also to a lot of unexpected behaviours, especially when talking about "updating" entries in the database (and here especially with complicated many-to-many-relationship).

So this architecture seems to be fine in a "short-lived-context" (like asp.net MVC is), but not in a "long-lived-context".

Did you experience the same/similar problems? How did you handle them?

来源:https://stackoverflow.com/questions/30068980/entity-framework-architecture-for-wpf-mvvm-applications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!