Initial support for relational query flattening

Turns SelectMany into a single SQL query.