Generalize `ToExpression` casts for SelectQuery.