title: Generic repository select by ID in EF4
body: <p>So I'm trying to create a generic select by ID method for a base repository class. In order to achieve this I'm using EF4 with POCO's. I created an interface with a getter called Id and successfully modified the T4 template in order to have a generic Id property in all the entities that returns the PK.</p>
  
  <p>The problem comes when I use the query. I'm implementing it like this:</p>
  
  <pre><code>public virtual T GetByID(int id)
  {
      return Database.ObjectSet&lt;T&gt;().SingleOrDefault(entity =&gt; entity.Id == id);
  }
  </code></pre>
  
  <p>And even though all the entities returned by the ObjectSet have the Id property set with their current primary key value, I'm getting a weird error: </p>
  
  <blockquote>
    <p>The specified type member 'Id' is not
    supported in LINQ to Entities. Only
    initializers, entity members, and
    entity navigation properties are
    supported.</p>
  </blockquote>
  
  <p>Am I missing something?</p>