I want to select the primary keys of a parent's child collection in a many-to-many relationship without using a join. Due to other constraints that have been removed from this example, the querying must occur on the child level (Tag) instead of parent level (Item).
Item item = null;
Tag tag = null;
var qoTags = QueryOver.Of<Tag>(() => tag)
.JoinQueryOver(x => x.Items, () => item)
.Select(Projections.Group<Item>(() => item.ItemId));
generates
SELECT Item.ItemId
FROM Tag
inner join ItemsTags on Tag.TagId = ItemsTags.TagId
inner join Item on ItemsTags.ItemId = Item.ItemId
GROUP BY Item.ItemId
but ideally, the generated SQL would be:
SELECT ItemsTags.ItemId
FROM Tag
inner join ItemsTags on Tag.TagId = ItemsTags.TagId
GROUP BY ItemsTags.ItemId
Notice the unnecessary join is removed and the 'group by' and 'select' clauses are referencing the junction table's ID's.
Thanks!