title: Problems with Generic Repository Pattern and Entity Framework
body: <p>There are a large number of examples on how to use the Generic Repository Pattern over Entitry Framework but none ever go into great detail.  More often than not the example they use for accessing data from a webapi is a one to one mapping to the model.</p>
  <p>For Eg. Get a single model object <code>_carRepository&lt;Car&gt;.Get(id);</code> or get all cars <code>_carRepository&lt;Car&gt;.GetAll();</code></p>
  <p>The way I have it implemented is in seperate layers like below:</p>
  <p><strong>Controller -&gt; Service Layer -&gt; Repository Layer -&gt; DataAccess</strong></p>
  <p>I have my service layer using AutoMapper where I map from the model(entity) to a DTO and that gets returned to the controller who returns that.</p>
  <p>The issue that I cant get my head around is how do I return an object from the repository layer which isnt of type &lt; T&gt;.</p>
  <p>Eg.  I want to return some data for a grid lets say a combination of multipe entities like a customers last number of purchases.  Am I supposed to pass the Customer, Product, Orders repository into the service and make multiple calls to the database and aggregate?  Or I was thinking in the cutomers repository just make a method which returns like a view dto of sorts already aggreating the data where it does a linq query and projects to this dto.  The issue I have is that I'm sure my repository shouldnt know about dto's?</p>
  <p>Would appreciate anyone who has thoughts on the correct way of doing this?</p>