title: Running inline SQL with Entity Framework 5 and returning tracked Entities
body: <p>How can I execute a command such as:</p>
  
  <p><code>SELECT * FROM CATS</code></p>
  
  <p>That behaves exactly as if I'd done <code>myContext.Cats.Where(c =&gt; true);</code> ?</p>
  
  <p>Google suggested <code>context.Database.ExecuteSqlCommand()</code> but that returns an int. There is also context.Database.SqlQuery which looks promising, but it says that entities returned are not tracked, which I suspect is important (I'm not really familiar with how EF works in terms of tracking things).</p>
  
  <p>It suggests using <code>System.Data.Entity.DbSet&lt;TEntity&gt;.SqlQuery(Object[])</code> to track it, but I'm not entirely sure what this means or how to implement it.</p>
  
  <p>In addition to make it even more confusing I want to write a generic method to allow me to execute the specific query against any table.</p>
  
  <p>Here's a rough example of what I'd like in pseudocode</p>
  
  <pre><code>public DbSet&lt;T&gt; ExecuteSelect&lt;T&gt;(DbContext context, string table)
  {
       DbSet&lt;T&gt; entities = context.RunSql("SELECT * FROM " + table);
  
       return entities;
  }
  </code></pre>
  
  <p>Any ideas?</p>