none
Just made a View Model, now how do I reconcile updates? RRS feed

  • Question

  • OK I just broke my old habits with the WinForms Treeview and made my first ViewModel against the WPF TreeView.  Now I'm stuck wondering how should I handle updates?

    I want to see how concurrent updates are handled.  I suppose the backend will be updated and that will update the datamodel, and then the end user will update the ViewModel.

    How would I reconcile these updates?  Does the new RIA technology in Silverlight 3 help me with this? What about Astoria/Ado.Net Data Services? 
    Tuesday, June 16, 2009 2:47 PM

Answers

  • You generally use properties in the View Model for updates... Take a look at the toolkit below which has a default template\sample projects .

    http://wpf.codeplex.com/Wiki/View.aspx?title=WPF%20Model-View-ViewModel%20Toolkit
    Tuesday, June 16, 2009 2:55 PM
    Moderator
  • In my own project wich is MultiTier I have the following

    WCF LinqToSQL wich creates models from the SQL data and the other way around.
    My WCF self exposes some methods to get my objects or save them.

    My WPF application uses these methods to get the data and put them in there respective ViewModels and Collections.
    Validation of data is done in the ViewModels with IDataError and I use simple SaveButtons to start saving the changed data of the collection.
    When a save is called I get the Model out of the ViewModel and send them back over the line to WCF
    Thursday, June 18, 2009 2:14 PM

All replies

  • You generally use properties in the View Model for updates... Take a look at the toolkit below which has a default template\sample projects .

    http://wpf.codeplex.com/Wiki/View.aspx?title=WPF%20Model-View-ViewModel%20Toolkit
    Tuesday, June 16, 2009 2:55 PM
    Moderator
  • Thank you for the reply. It took me a while to figure out that this sample is actually available under the WPF Futures section of the current wpf.codeplex.com website.

    Whew, this code is a bit to digest (being new to this layout)... Are you planning on releasing some documentation that explains what is going on here? Or at least highlight the main points of interest?

    For example, it seems interesting to me that all the code hinges on the public static property MainViewModel.Current. Also, it isn't clear how this project helps me understand Josh Smith's approach to a ViewModel in this project:

    http://www.codeproject.com/KB/WPF/TreeViewWithViewModel.aspx

    Here, Josh recursively re-wraps the source object into a treeview object. The one thing that is missing is how do I handle updates... Do I update the viewmodel, the underlying model, or both.
    Wednesday, June 17, 2009 11:31 PM
  • Your GUI and your Controllers should both update the ViewModel. Because your ViewModel uses INotifyPropertyChanged the GUI will know if an property is updated by a controller and vise versa.

    Your ViewModel has a reference to your model and it's property, and your ViewModel will thus update your models data. I can post some code if this explenation does not help you enough.

    Thursday, June 18, 2009 7:50 AM
  • (For these examples, I'm working conceptually off the Treeview MVC model written up by Josh Smith)

    [Part 1]
    Let me see if I got this right: Suppose an update goes from the ViewModel to the Model; The ViewModel takes responsibility for (1) Calling INotifyPropertyChanged (2) updating the underlying Model? In the case the Model is a recordset of some type (Astoria/SQL/etc.), then how are changes reconciled to the backend database?

    [Part 2]
    Suppose that during the update to the backend, conflicts were detected, how is that updated to the treeview? Where does the Try{}Catch{} occur, where should exceptions be handled?

    [Part 3]
    Generally speaking, how would the backend store (SQL, Azure Tables, etc.) notify and reconcle updates to the Model and the ViewModel?

    [Part 4]
    Where in this architecture would you place the generated code (wrapper classes) from WCF/Astoria/AzureTables/ or Azure SQL Services?

    Thursday, June 18, 2009 2:05 PM
  • Just thought of a different scenario...

    [Part 5]
    Does RIA Services automate any of this work, or otherwise assist with using the MVVM in enterprise envrionments?

    [Part 6]
    Is the Enterprise Lib aligned with MVVM; Are the WPF groups and EntLib groups aware of each other? ( http://www.codeplex.com/entlib )
    Thursday, June 18, 2009 2:10 PM
  • I would not directly use the SQL objects.

    Use a controller to get your SQL objects and convert them to a nice model.

    Then depending on how you want to save you can do two things. first have a savebutton that calls a save method on the controller.
    second is using the INotifyPropertyChanged. Let your controller hookup to every VM you have of your model and take the appropiate actions when something has changed in the moddel.

    In your VM you can implement IDataError to report back errors with validating or other propertys.
    Thursday, June 18, 2009 2:10 PM
  • In my own project wich is MultiTier I have the following

    WCF LinqToSQL wich creates models from the SQL data and the other way around.
    My WCF self exposes some methods to get my objects or save them.

    My WPF application uses these methods to get the data and put them in there respective ViewModels and Collections.
    Validation of data is done in the ViewModels with IDataError and I use simple SaveButtons to start saving the changed data of the collection.
    When a save is called I get the Model out of the ViewModel and send them back over the line to WCF
    Thursday, June 18, 2009 2:14 PM