Brad Laney
unread,Jun 24, 2011, 11:27:28 AM6/24/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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