title: Adding functionality to EF Model POCO collections for GUI
body: <p>I’m having some difficulty working out the best way of approaching a design problem. I was hoping for some ideas / advice. It’s a WPF 4.0 desktop application.</p>
  
  <p>I’m using Entity Framework (v6, model first) and it has generated <code>ObservableCollection</code>s of POCO classes for me which I’m using as the basis for my Model. I’m exposing these to my ViewModel and my intention is to expose (<code>ReadOnly</code> versions of) the collections from here to my View, but I need to add some behaviour to each object in the collection before the interface will function (this is very much “View” functionality – recording user interface state corresponding to each member of the collection, not data that should be persisted).</p>
  
  <p>As I see it, I’ve got two options:</p>
  
  <ol>
  <li>Add behaviour to the generated POCO classes though additional partial class definitions. This seems wrong because the POCO classes are Model classes and the functionality I need is not Model functionality.</li>
  <li>Create a new class (or sub-class) for use in the ViewModel collections and synchronise the collections between the Model and the VM. The synchronisation and duplication of data seems like an ugly kludge, not to mention significant extra implementation work and runtime processing. <strong>[EDIT: It has been suggested (not unreasonably) that this could be achieved by wrapping the original POCO objects in classes that add functionality. See below for why this is more complicated than it might first appear]</strong></li>
  </ol>
  
  <p>Is there a standard way to approach this sort of problem ?</p>
  
  <p><strong>Edit: make the problem parameters more specific</strong></p>
  
  <p>I have a collection of <code>X</code>s, each of which holds a collection of <code>Y</code>s (because of a one -> many relationship in the DB). For Option 2 above, I would need to wrap all the <code>X</code>s and all the <code>Y</code>s. I can create a collection of <code>WrappedX</code>s relatively easily, but I can't easily go in and change each <code>X</code>'s member collection to <code>WrappedY</code>s. I'd have to clone the <code>Y</code> collections in the wrapper for X and keep all of the <code>Y</code> &lt;> <code>WrappedY</code> collections in sync. This is the overhead that makes me uncomfortable implemnting Option 2 if there is a better way.</p>