mardi 5 mai 2015

Entity framework architecture for WPF MVVM applications

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:

Entity Framework with(out) Repository and Unit Of Work

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?

Aucun commentaire:

Enregistrer un commentaire