title: In EF6, how to create a generic method to get entities using a common field/column
body: <p>im sorry if the title isnt enlightening enough after a while i couldnt come with a phrase to explain my problem.</p>
  
  <p>Its like this:
  I'm using EF6, Database first approach. All my entities have an ID and an Enabled property.
  I have the EDMX file on my DAL and now i need to design the Business Layer (BLL for me).</p>
  
  <p>Since i will need to validate what data comes from the DAL and is visible to the rest of the app i decided to create an interface for the common operators, create a base class that implements that and have all my custom database-tables\entities providers inherit that.</p>
  
  <p>If that doesnt make sense, here is what i'm doing: (All of this is in BLL)</p>
  
  <pre><code>public interface IEntityManager&lt;T&gt; where T : class {
          void Add(T e, bool commit=false);
          void Delete(T e);
          void DeleteByID(int id);
          void Update(T e);
          IQueryable&lt;T&gt; Search(Expression&lt;Func&lt;T, bool&gt;&gt; predicate);
          IQueryable&lt;T&gt; GetAll();
          T Get(int id);
      }
  </code></pre>
  
  <p>Now, the base class that implements the common operations is this: (edited for readability and brevity)</p>
  
  <pre><code> public class EntityManager&lt;TEntity&gt; : IDisposable, IEntityManager&lt;TEntity&gt; where TEntity : class {
          private readonly DbContext _ctx;
          private readonly DbSet&lt;TEntity&gt; _set;
  
          public EntityManager() {
              _ctx = new DomainModelFactory();
              _set = _ctx.Set&lt;TEntity&gt;();
          }
  
          public void Add(TEntity e) {
              _set.AddOrUpdate(e);
          }            
  
  //other methods here
  
          public TEntity Get(int id) {
              return _set.Find(id);
          }
  
  
      }
  </code></pre>
  
  <p>To create managers that will actually access the data and make it usable across the application, i'm planning on doing something like:</p>
  
  <pre><code>public class VenueManager: EntityManager&lt;Venue&gt; {
          public VenueManager():base()  {
          }
      }
  </code></pre>
  
  <p>For the class that will manage my Venue entity. I am creating classes instead of using something like</p>
  
  <pre><code>var venueManager = new EntityManager&lt;Venue&gt;();
  </code></pre>
  
  <p>because these classes will have some specialized methods.
  I hope you could understand what i have done so far (and it works)</p>
  
  <p>Now, my problem is that every entity has two common fields: ID (int) and Enabled (bool)
  I am to use these when deleting by id and when coding Get and GetAll because i must only 
  get items that have Enabled=true. Now, i know that since i'm create Manager classes i could just use c&amp;p the code, but i was wondering, is there a way that i can code this in the EntityManager class and have all the managers inherit the method but using the concrete classes ?</p>
  
  <p>something like this:
  In EntityManager class:</p>
  
  <pre><code> public TEntity Get(int id) {
              return _set.Where(T.ID==id);
          }
  </code></pre>
  
  <p>Thats basically what i want: a way to use these properties at the base class (EntityManager) where they matter (methods deletebyid, get and getall) in a way that all Manager classes (ManagerVenue in the example) inherit these methods so that i wont have to write them all over and over? (got some 100 entities) </p>