// this will hold the criterial for the query
var subQuery = QueryOver.Of<Parent>();
// we build the criteria here...
// add paging id projection so we only get one page of ids
var pageSubQuery = subQuery.Clone()
.OrderBy(p => p.Id).Asc
.Select(p => p.Id)
.Skip(index ?? 0)
.Take(itemsPerPage ?? 20)
;
var items = session.QueryOver<Parent>()
.WithSubquery.WhereProperty(p => p.Id).In(pageSubQuery)
.OrderBy(p => p.Id).Asc // important to have the
same order as above!
.Fetch(p => p.Children).Eager
.TransformUsing(new DistinctRootEntityResultTransformer())
.Future()
;
// Count
var count = subQuery.GetExecutableQueryOver(session)
.Select(Projections.CountDistinct<Parent>(p => p.Id))
.FutureValue<int>()
;
By applying the paging on the subquery it gives us a list of the ids
of the parents on the first page. We then use this as the source for a
"where Id in (criteria)" statement that we know will only return the
right amount of parent records and we can fetch the children without
needing additional criteria on the outer query.
It works for us, but there might be a better way...
note: We use future values so that we get one trip to the database
that gives us the total count of parents matching the criteria and one
page of parents with their children.
-joe
> --
> You received this message because you are subscribed to the Google Groups "nhusers" group.
> To post to this group, send email to nhu...@googlegroups.com.
> To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
>
>