Hello,
I am attempting to query for a count of the related items in a many-to-many
relationship without having to map the join table, ex:
(Foo) 1--* (FooBar) *--1 (Bar)
I have modeled this relationship without the join table (FooBar) being
mapped, i.e. each map has a Set that is configured as a many-to-many
relationship:
Foo.Bars
Bar.Foos
To get the count of Bars in each Foo, the only way I have found is to join
to the Bar table like this:
var countQuery = DetachedCriteria.For<Foo>("f")
.CreateCriteria("Bars", "b")
.Add(Restrictions.EqProperty("primary.Id", "f.Id"))
.Select(Projections.Count("b.Id"));
session.QueryOver<Foo>("primary")
.Select(
Projections.Id(),
Projections.SubQuery(countQuery));
However this does a double join from Foo to FooBars to Bars, when really
all the data I need is contained in the join table. Is there a way to avoid
the joins without creating a mapping the FooBar table and without using a
direct SQL query?
Thanks,
Dave
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.