title: Best Practice Entity Framework Models vs ViewModels
body: <p>From what I read, I understand that we should always pass a viewmodel to the view. However, sometimes this viewmodel is exactly or almost the same as the EF-model. Is it acceptable or is there any workaround to this problem (repetitive code) ?</p>
  
  <p>For example, if I have this EF-Model :</p>
  
  <pre><code>class UserModel
  {
      string id {get;set}
      string name {get;set}
      string address {get;set}
      string phone {get;set}
      string website {get;set}
  }
  </code></pre>
  
  <p>How should the viewmodel be ... like this :</p>
  
  <pre><code>class UserViewModel
  {
      string name {get;set}
      string address {get;set}
      string otherobject {get;set}
  }
  </code></pre>
  
  <p>Or Like this : </p>
  
  <pre><code>class UserViewModel
  {
      UserModel user;
      string otherobject {get;set}
  }
  </code></pre>
  
  <p>With option #1, properties are repeated... and in another viewmodel they will be repeated again. And I will need to repeat all data annotations on each viewmodels. However, I send only the properties that I need. </p>
  
  <p>With option #2, nothing is repeated, but I pass a lot of properties that I don't need.</p>
  
  <p>The last option would be to mix option #1 and option #2 according to the needs... but I don't like this option because of the lack of a common standard. Sometimes the properties will be defined and datannoted in the viewmodels and sometimes in the EF-model. </p>
  
  <p>I wish there is an option #4 that I don't see...?</p>
  
  <p>Thank you.</p>