Cast a IQueryable type to interface in Linq to Entities <p>I have the following method in my generic class:</p> <pre><code>// This is the class declaration public abstract class BaseService&lt;TEntity, TKey&gt; : IBaseService&lt;TEntity, TKey&gt; where TEntity : class, IEntity&lt;TKey&gt; // The Method public IQueryable&lt;TEntity&gt; GetActive() { if (typeof(IActivable).IsAssignableFrom(typeof(TEntity))) { return this.repository.Get().Cast&lt;IActivable&gt;() .Where(q =&gt; q.Active) .Cast&lt;TEntity&gt;(); } else { return this.Get(); } } </code></pre> <p>This is the interface:</p> <pre><code>public interface IActivable { bool Active { get; set; } } </code></pre> <p>Basically, <code>TEntity</code> is an Entity (POCO) class, that can implement IActivable if they have <code>Active</code> property. I want to the method to return all records that have <code>Active</code> value true. However, I have this error:</p> <blockquote> <p>Unable to cast the type 'WebTest.Models.Entities.Product' to type 'Data.IActivable'. LINQ to Entities only supports casting EDM primitive or enumeration types.</p> </blockquote> <p>I understand why this error occurs. But the articles on SO does not have any valid solution for my case. Is it achievable with <code>Cast</code>, or any other way? Note: I do not want to convert to <code>IEnumerable</code>, I want to keep <code>IQueryable</code>.</p>