title: Generic Query with Entity Framework 4. Generic Repository?
body: <p>This is my Database Structure : <br />
  <strong>Company</strong><br />
  CompanyID<br />
  CompanyName<br />
  ...<br /></p>
  
  <p><strong>Location</strong><br />
  LocationID<br />
  LocationName<br />
  ...<br /></p>
  
  <p><strong>Contact</strong><br />
  ContactID<br />
  ContactName<br />
  ContactEmail<br /></p>
  
  <p><strong>CompanyContact</strong><br />
  ContactID<br />
  CompanyID<br />
  IsActive<br /></p>
  
  <p><strong>LocationContact</strong><br />
  ContactID<br />
  LocationID<br />
  IsActive<br /></p>
  
  <p>Now I have a repository for each of these entity (CompanyContact, LocationContact)<br /></p>
  
  <pre><code>public List&lt;Contact&gt; GetCompanyContact(int CompanyID)
  {
     return _context.CompanyContacts.Where(p =&gt; p.CompanyID == CompanyID).Select(s =&gt; s.Contact).ToList();
  }
  ...
  public List&lt;Contact&gt; GetLocationContact(int LocationID)
  {
     return _context.LocationContacts.Where(p =&gt; p.LocationID == LocationID).Select(s =&gt; s.Contact).ToList();
  }
  ...
  </code></pre>
  
  <p>How Can I create a Generic method to get the List of contact. 
  I would like to pass, the EntityName(CompanyContact or LocationContact) with the Reference Column name(CompanyID, LocationID).<br />
  Example of What I want :</p>
  
  <pre><code>public List&lt;Contact&gt; GetContact(string EntityName,String ColName){....}
  Ex of call .
  GetContact("CompanyContact","CompanyID");
  </code></pre>
  
  <p>Thx a lot.
  <br /><br />
  <strong>EDIT</strong><br />
  A Company can have Many Contact and a Location can have many contact too.</p>