title: Check if entity implements interface and add predicate in generic repo
body: <p>Some of my entities have <code>IEnabledEntity</code> interface.
  I want to check in repository if entity implements interface then add some predicate. I have the following code:</p>
  
  <pre><code>public class Repository&lt;T&gt; : IRepository&lt;T&gt; where T : class, IEntity, new()
  {
     public IQueryable&lt;T&gt; Get(Expression&lt;Func&lt;T, bool&gt;&gt; predicate, params string[] includes)
       IQueryable&lt;T&gt; query = Context.Set&lt;T&gt;();
       foreach (var include in includes)
       {
          query = query.Include(include);
       }
  
       query = query.Where(predicate);
  
       var isEnabledEntity = typeof(IEnabledEntity).IsAssignableFrom(typeof(T));
  
       if (isEnabledEntity)
       {
          query = query.Where(e =&gt; ((IEnabledEntity) e).IsEnabled);
       }
  
       return query;
  }
  
   public interface IEnabledEntity
   {
      bool IsEnabled { get; set; }
   }
  
   public class Test : IBaseEntity, IEnabledEntity
   {
      // ...
      public bool IsEnabled { get; set; }
   }
  </code></pre>
  
  <p>But, I get exception about casting:</p>
  
  <p><code>Unable to cast the type 'Domain.Test' to type 'Domain.Interfaces.IEnabledEntity'. LINQ to Entities only supports casting EDM primitive or enumeration types.
  </code></p>
  
  <p>How to make it work?</p>