I do the cast in line 429 & 430 before building the query.