Note that the following does not solve the problem that the OP has, since the join predicate depends on each element. The following helps if the condition is known for the entire query immediately:
You shared the request:
var part1 = from x in db.products where x.id == id select x; var part2 = b ? (from x in part1 join db.category1 select { x, joinedItem }) : (from x in part1 join db.category2 select { x, joinedItem });
Quickly recorded. You need to make anonymous types compatible for both queries. This is the only important thing.
source share