title: Designing an MVC repository using ViewModels
body: <p>I want to create a repository class to separate out my data logic from my controllers.  I am using a ViewModel to represent some data that will be filled with data from different tables.</p>
  
  <p>Here are some questions  I have:</p>
  
  <ol>
  <li>For a method like <code>GetAll()</code>, do I return an <code>IQueryable&lt;MyViewModel&gt;</code> or <code>IQueryable&lt;Entity&gt;</code>?  If I return viewmodels, how do I cope with a <code>GetAll()</code> that pulls thousands of records?  </li>
  <li>Do I create a constructor for my custom ViewModel class that takes the Entity as a parameter to do the mapping?  (I'm still unfamiliar with automapper so just need an understanding on how to do this from a design point of view)</li>
  </ol>
  
  <p>Again, my main concern is a method like <code>GetAll()</code> which would pull many records.  If I did a foreach loop to translate each Entity into a ViewModel seems like a lot of overhead.  My thought was to put a reference inside the custom ViewModel class to the <code>IQueryable&lt;Entity&gt;</code> to access from the collection, and have the ListViewModel just have indexers or something like that which reference the collection property.</p>