What I want to do is display a simple data grid that contains entity data and the aggregate data of my children. For example, you can use order and position. I want to display order information and the number of items.
OrderID, OrderDate, NumOfLineItems
Now, as a rule, in SQL you can do it differently. But this is the only way I could think that this might work when translating to NHibernate.
SELECT o.OrderID, OrderDate, NumOfLineItems
FROM
INNER JOIN
(SELECT o2.OrderID, COUNT(*) As NumOfLineItems FROM
INNER JOIN
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 about how NHibernate will allow me to use the QueryOver syntax. I do not want to use derived columns. I am trying to avoid writing SQL.
For my entities, I have an Order object and an AggregatedOrder object, which will be my DTO in this case, and I plan to use an aliastobean transformer to copy data into it.
I just don’t know how to understand this.
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);
source
share