tags:

views:

563

answers:

3

I have written a small helper for doing client-side change tracking objects/dtos to use in my ViewModels (see http://viss.be/2009/04/02/modelviewcontext-client-side-change-tracking/)

I didn't find a lot of resources about the subject. So I wonder; how do you typically handle it?

Thanks, Marc

A: 

A ViewModel is all about binding the View (UI) to the Model (data). So it should not be responsible for tracking changes, that is something you should be doing inside of you Model classes as they contain the data.

To notify the UI both Model and ViewModel implement INotyfyPorpertyChanged. The ViewModel catches the Model events and propagates them to the View as needed.

See http://msmvps.com/blogs/theproblemsolver/archive/2009/04/07/using-model-view-viewmodel-with-silverlight.aspx for a more complete example.

Maurice
I understand this, and then again not. Models don't live at the client side very often. Am I wrong to state that the Models in MVVM tend to be DTOs?
A model is the data with business rules. In simple case with little business rules it could be just a DTO. In a more complex case a DTO migth be used to get the data into the client and then the full Model is created. See http://tinyurl.com/dhvkf9 for a blog post I did explaining MVVM in Silverlight
Maurice
Ok, that's the part that I'm not buying. The "domain/business" model doesn't exist at the client side in my books... By the way; How do you deal with persistence in your scenario?
Persistence is done on the server. How this is done depends on the situation but ADO.NET Data Services (AKA Astoria) is one of the possible solutions as is the .NET RIA services.For some examples think about GMail. All logic is client side not on the server, that is just a gateway to get the data.
Maurice
A: 

I may need to make it more clear what the ViewModelContext is.

The ViewModelContext is a gateway to the model which is exposed by the ViewModel to the view (instead of exposing the model directly).

All the context does is monitor the model, and when it changes states (via code inside commands or databinding) it updates some change tracking information on the model.

The ViewModel itself can react on that when it happens, or could query that change tracking information much later (for instance on a save command). And also; the view can directly databind to this information (eg. a view could filter on items that have IsDeleted on true).

So, I'm actually taking change tracking out of the ViewModel whereas in most implementation of ViewModel that I have seen, some form of change track is always present inside the ViewModels (eg. ListOfRemovedItems, etc...)

Any thoughts?

A: 

I didn't find a lot of resources about the subject.

I too want to see more discussion on this topic

So I wonder; how do you typically handle it?

  1. Just use DataSet.
  2. Keep looking for solutions.
Sake