title: Working with an ObservableCollection based on an Entity Framework one to many property
body: <p>Working with WPF in MVVM. I have a ViewModel with a CurrentItem property. This is an Item object which is pulled directly from Entity Framework. Item has a collection of Property objects.</p>
  
  <pre><code>public virtual ICollection&lt;Property&gt; Properties { get; set; }
  </code></pre>
  
  <p>In the View, I need users to be able to add and remove objects from this collection. To do that, I need to create an <code>ObservableCollection&lt;Property&gt;</code>, which we'll call ItemProperties.</p>
  
  <p>There are various ways to do this. The most obvious is to add a <code>ObservableCollection&lt;Property&gt;</code> property on the ViewModel. Then populate this in the constructor, like so:</p>
  
  <pre><code>ItemProperties = new ObservableCollection&lt;Property&gt;(CurrentItem.Properties);
  </code></pre>
  
  <p>It's also possible to create an ObservableCollection wrapper that sits over the top of the real collection:</p>
  
  <pre><code>public ObservableCollection&lt;Property&gt; ItemProperties
  {
      get
      {
          return new ObservableCollection&lt;Property&gt;(CurrentItem.Properties);
      }
      set
      {
          CurrentItem.Properties = value.ToList();
          OnPropertyChanged("ItemProperties");
      }
  }
  </code></pre>
  
  <p>Which has its own problems. You can't just <code>Add()</code> to this collection, since it'll <code>get</code> first, meaning the collection remains unchanged. So you'd either have to spin up a new collection, add to that, and then assign its value to the property or raise the <code>OnPropertyChanged</code> event outside the property. Either of which also sounds like a maintenance issue.</p>
  
  <p>Is there a more effective way of doing this, which allows you to access the EF property list directly?</p>