I tried to use the MVVM design pattern with WPF and Entity Framework to create a simple application. Everything goes well and well if the classes are loosely coupled, but if I have sth. as two classes of models: Client and Address, and the Client has a collection of Addresses.
Now for these classes I need to create two VM classes - CustomerVM and AddressVM. CustomerVM must have an ObservableCollection of AddressVM objects. Every change made to these VM classes (including all CRUD operations for both CustomerVM and AddressVM) should be reflected in the model classes - this is why I end up finding a code entry, for example. subscribes to the modified ObservableCollection event, and if a new object is added, add a new object to the model ... and so on ...
What to do about it? Is this the usual use of MVVM? Am I doing everything right? How to reduce the amount of code needed for such a simple class hierarchy? Are there any environments that can create VM base classes that "behave" well with other classes in the hierarchy? What if class relationships become MORE complex?
OR DELIVERY IS SIMPLY:
How to reflect changes made in vm collections to model collections:
CustomerVM1.AdressesVM.Add(new AddressVM{City="New York"})
should call the equivalent:
Customer1.Adresses.Add(new Address{City="New York"})
There is the same problem in the opposite direction - how to reflect the changes made to the collections in the model, which will be included in the presentation model, but I'm more interested in the first one, because it has a more practical application and vm objects can be easily recreated in most cases.