title: Pass Entity Framework type to generic method
body: <p>In my project using Entity Framework, I have a bunch of functions that look almost exactly alike, so I want to created a generic method they call:</p>
  
  
  
  <pre class="lang-cs prettyprint-override"><code>private IHttpActionResult GetData&lt;TEntity&gt;(DbSet&lt;TEntity&gt; data) 
  </code></pre>
  
  <p>The problem I'm having is that the <code>data</code> parameter is saying <code>TEntity</code> has to be a reference type to work, but the type of the entity comes from auto-generated code that doesn't have any base class that I can constrain via a <code>where</code> clause on the method definition.</p>
  
  <p>I'd basically want to call it by getting a context and passing the table in like so:</p>
  
  <pre class="lang-cs prettyprint-override"><code>using (var context = new DataModel.MyEntities()) {
      GetData(context.Lab_SubSpace_Contact);
  }
  </code></pre>