NHibernate QueryOver select entity and aggregates

331 views
Skip to first unread message

Brad Laney

unread,
Jun 24, 2011, 11:27:28 AM6/24/11
to nhusers
What I want to do is display a simple grid of data which contains the
entity data, and the aggregate data of its children. For example lets
use a Order and line items. I want to display the order information,
and the count of line items.

OrderID, OrderDate, NumOfLineItems

Now normally in SQL you can do it many ways. But this is the only way
I could think of that might work when translating to NHibernate.

SELECT o.OrderID, OrderDate, NumOfLineItems
FROM #Orders o
INNER JOIN
(SELECT o2.OrderID, COUNT(*) As NumOfLineItems FROM #LineItems l
INNER JOIN #Orders o2 ON o2.OrderID = l.OrderID
WHERE UserID = 1 GROUP BY o2.OrderID) t1 ON o.OrderID = t1.OrderID
WHERE UserID = 1
I know there are other ways, but I'm trying to think of ways that
NHibernate will allow me to do using QueryOver syntax. I do not want
to use derived columns. I am trying to avoid writing SQL.

For my entities I have an Order entity, and an AggregatedOrder entity,
which will be my DTO in this case, and I plan to use the transformer
aliastobean to copy the data into it.

I just have absolutely no idea how to figure this out.

All I have so far:

QueryOver<LineItem> x = QueryOver.Of<LineItem>()
.SelectList(p => p .SelectCount(l => l.Id).WithAlias(() =>
itemAlias.NumOfLineItems))
.JoinQueryOver<Order>(l => l.Order)
.Where(o => o.UserID == userID)


var y = session.QueryOver<Listing>()
.JoinQueryOver<Bid>(x); // no idea whats going on here

Michael Möhle

unread,
Jun 27, 2011, 3:32:05 PM6/27/11
to nhu...@googlegroups.com
Maybe this
http://nhforge.org/blogs/nhibernate/archive/2009/12/17/queryover-in-nh-3-0.a
spx
Will help you.
Kombination of Aliases and Projections

Michael

OrderID, OrderDate, NumOfLineItems

--
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.

Reply all
Reply to author
Forward
0 new messages