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:
If all DbSets has the 'UserID' property then create another interface named 'IUserID' and then try this code:
protected TEntity GetByUserID(Guid userID) where TEntity : class
{
var user = this.Set()
.ToList()
.Cast()
.Where(u => (!u.IsDeleted))
.Cast()
.Where(u => (u.UserID == userID))
.FirstOrDefault();
return user;
}