title: Does converting from DbSet to IEnumerable cause the query to execute?
body: <p>I have the following 2 methods in my Logs repository. </p>
  
  <pre><code>public IEnumerable&lt;Log&gt; GetAll()
  {
     var db = new CasLogEntities();
     return db.Logs;
  }           
  
  
  public DbSet&lt;Log&gt; GetAllSet()
  {
     var db = new CasLogEntities();
     return db.Logs;
  }           
  </code></pre>
  
  <p>The only difference is that one returns an IEnumerable of Log and the other a DbSet of Log.</p>
  
  <p>In My Asset Controller I have the following code</p>
  
  <pre><code>var allLogs = _logRepo.GetAllSet();
  var Logs = (from log in allLogs
                group log by log.DeviceId
                into l
                select new {DeviceId = l.Key, TimeStamp = l.Max(s =&gt; s.TimeStamp)}).ToList();
  </code></pre>
  
  <p>Now the issues is that I am getting massive performance difference in the group by statement depending on which one of the repo methods I call. </p>
  
  <ul>
  <li>getAllSet which returns the DbSet is lightning fast, </li>
  <li>GetAll returns IEnumerable is reallllyyyy slow. </li>
  </ul>
  
  <p>Can anybody explain this. I was thinking that the conversion of the DbSet to the IEnumerable in the GetAll was causing the Query to execute and hence I was doing the group by on a massive in memory set. While as the GetAllSet was deferring the query execution until the "ToList()" and hence was doing the group by work on the server.</p>
  
  <p>Is this correct? Is there another way to explain this?</p>
  
  <p>I would prefer for the GetAll to return the IEnumerable as I am more familiar with it and its a bit easier for testing.</p>