title: How to present a Collection of (View)Models in a ViewModel
body: <p>I have a question regarding the MVVM design for C#/WPF. I've had a look at several demo applications, but they didn't really handle my problem.
  My application consists of objects that contain other objects. Much like in a parent - children relationship. </p>
  
  <p>My question now is: </p>
  
  <ul>
  <li>does the children attribute have to be a ViewModel</li>
  <li>and if so, how do I create new Parent objects, which contain the <strong>existing</strong> Child objects via ViewModels?</li>
  </ul>
  
  <p>I have sth like the following scenario:</p>
  
  <pre><code>class Child {
      string Name;
  }
  
  class ChildVM {
      Child _child;
      string Name{return _child.Name;}
  }
  
  class Parent {
      string Name;
      List&lt;Child&gt; children;
  }
  
  class ParentVM{
      Parent _parent;
  
      string Name{return _parent.Name;}
      List&lt;ChildVM&gt; children {get;set;}
  
      ParentVM(Parent p){_parent = p;}
  }
  
  void CreateANewParent(){
      List&lt;ChildVM&gt; children = new List&lt;ChildVM&gt;(){new ChildVM(new Child()),...};
      ParentVM parent = new ParentVM(new Parent());
      foreach(ChildVM child in children)
          parent.children.Add(child);
  }
  </code></pre>
  
  <p>The problem here is, that the ParentVM contains the ChildVM, BUT the actual Parent (which is inside of the ParentVM) does not have the Child objects contained by the ChildVM objects. I also don't think it's a good idea to duplicate the Child objects, as it leads to redundance and in my application context there is also no need/possibility to create new Child objects.</p>
  
  <p>I also thought about the following class design:</p>
  
  <pre><code>class ParentVM {
      Parent _parent;
  
      string Name{return _parent.Name;}
      List&lt;Child&gt; children {get{return _parent.Children;}}
  }
  </code></pre>
  
  <p>However, this would mean I would directly operate on the Model if I want to manipulate a ParentVM's Child object.</p>
  
  <p>On the other hand I could simply leave the (Model) Parent blank and use the ParentVM to create a new Parent in the database. But is this a good way of handling the problem?</p>