title: MVC Repository Pattern - when to use AutoMapper?
body: <p>We used Telerik ORM to generate our domain models and have these in a class library that is called the DAL. Then we have our UI project which is a MVC 4 web application. In this, we have repositories and models. The models here are the viewmodels, specifically to display data on the views. </p>
  
  <p>Now my questions are:</p>
  
  <ol>
  <li>Should the repository directly return back the viewmodel?</li>
  <li>Should the viewmodel be converted to an entity?</li>
  <li>What's overhead in using automapper? Where should it be used? </li>
  </ol>
  
  <p>If we do not convert to the viewmodel in the repository using automapper, we might have different calls to the db to populate each part of the object. A viewmodel for a page might have list of contacts, and a selected contact. The selected contact will be populated with one call to the repository and the list of contacts will be populated with another call. Also if the mapper is at the repository level, wouldn't it be better to remove all the 'extra fields' like gender if we're only interested in 'name and id'?</p>
  
  <p>I have heard that the repository should not return view models because viewmodels are specific to UI and should not be involved in the data layer. Is this true?</p>