[linq] Use hashtable lookup instead of linear scan for groupby keys. Fixes #18673

(cherry picked from commit f1790decb8db018578f2ff476618aabcb110fc06)