title: ASP.NET MVC2 with Entity Framework 4 - AsEnumerable() or ToList() in repository?
body: <p>So I've been advised a few times to disable lazy loading when building an application with the above frameworks, and that ToList() will force the queries in my repository to execute.  I was told that I would avoid certain "traps" I might run into if I used AsEnumerable().  </p>
  
  <p>On a recent question, however, I included a bunch of ToList()s in my code examples, and startled a number of people that assured me IEnumerable is much better to return.</p>
  
  <p>I'm thoroughly confused now, to say the least.</p>
  
  <p>Should I be returning IEnumerable in my repository, then converting them to List in my view models?  Should I use ToList() straightaway in my repository like I was before?  Was I suppose to leave deferred execution enabled in the first place?</p>
  
  <p>Jiminy Christmas...</p>
  
  <p><strong>Edit:</strong>
  So, being that I disabled lazy loading, based on earlier advice, should I then re-enable it, return IEnumerable / IQueryable from my repository, and convert the collection to a List in my view models, if needed?</p>
  
  <p>One of the answers below associates IEnumerable with eager execution, while I was under the impression that only ToList() would force immediate execution of the query.</p>
  
  <p>I stumbled across <a href="http://mikehadlow.blogspot.com/2009/01/should-my-repository-expose-iqueryable.html" rel="nofollow noreferrer">this</a>, <a href="https://stackoverflow.com/questions/718624/to-return-iqueryablet-or-not-return-iqueryablet">this</a>, and <a href="https://stackoverflow.com/questions/1699607/asp-mvc-repository-that-reflects-iqueryable-but-not-linq-to-sql-ddd-how-to-ques/1699756#1699756">this</a> that all contain some interesting discussion related to this question.</p>