Object persistance using MVVM
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Object persistance using MVVM

  1. #1
    Join Date
    Aug 2009
    Posts
    2

    Object persistance using MVVM

    This forum seems a bit quiet, if you cant answer my question, could you possibly point out a good forum that deals with the MVVM pattern?

    MY QUESTION:

    I am using WPF and the MVVM architecture. The problem is that I have a user control that edits the properties of an object. All the textbox's are bound to the relevant object in my model (through the viewmodel).

    I want to know what to do when the user DOESNT save this information (they may navigate away, or press the cancel button). The problem is that if they edit the textbox, the model gets changed without the model being persisted to the database. So if they come back to view that object, it will appear as though the changes they made, last time when they were looking at the object, have changed the database. Of course they havent. I want the model to reflect the database. How is everyone solving this simple problem.

    Does this make sense?

    Its a very simple problem, but i dont know how everyone is getting around it.. what is the design pattern commonly used to solve this problem?

  2. #2
    Arjay's Avatar
    Arjay is online now Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,254

    Re: Object persistance using MVVM

    One approach is to make a copy of the VM when the control loads (and bind the control to the copy). If the data is saved update the real VM and persist to the db.

  3. #3
    Arjay's Avatar
    Arjay is online now Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,254

    Re: Object persistance using MVVM

    Oh, and welcome to the forum.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center