title: Generics and Entity Framework: How do I return a different type depending on a column value
body: <p>We have a Persons table which stores different types of persons (Buyer, Seller, Agent, etc).  Our ORM is Entity Framework CodeFirst (CTP5).  We're using the repository pattern for good TDD and mocking.  In the PersonRepository I want to return a specific type so I can do things like this:</p>
  
  <pre><code>Agent a = repository.Get&lt;Agent&gt;(5005);  // Where 5005 is just an example Id for the person
  a.SomeAgentProperty = someValue;
  Buyer b = repository.Get&lt;Buyer&gt;(253);   // Again, a simple PersonId.
  b.SomeBuyerProperty = someOtherValue;
  </code></pre>
  
  <p>The idea is that I know what kind of person I'm getting when I get it from the repository.  And, yes, I could just create X different Get methods called GetBuyer(int PersonId), GetSeller(int PersonId) and so on.  But that has a code smell.</p>
  
  <p>How would the generic function look?</p>
  
  <p>Here is my repository interface so far:</p>
  
  <pre><code>public interface IPersonRepository
  {
      Person Get(int PersonId);   // To get a generic person
      T Get&lt;T&gt;(int PersonId);     // To get a specific type of person (buyer, agent, etc.)
      void Save(Person person);
      void Delete(int p);
  }
  </code></pre>
  
  <p>And my concrete implementation:</p>
  
  <pre><code>    public T Get&lt;T&gt;(int PersonId)
      {
          //Here's my question: What goes here?
      }
  </code></pre>