I have a generic method to query objects of type TEntity in EF. I Want to add a condition as a where clause if TEntity implements a specific interface. The method I have is:
I think the problem might be the direct cast you are doing in your statement as well as query might be implementing enumeration types and so IDeletable is not implemented as on one entity.
LINQ-to-entities casting issue
proposed this solution.
return query.ToList()
.Cast()
.Where( e => e.Deleted )
.Cast();