Hi,
I need some help with counting the number of products sold. It is quite easy to get the result with only SQL, but I completly do not know how to do it with HQL.
My tables look as follows:
Products:
Id | InvoiceId | Amount | Price | ...
Invoices
Id | ...
I need to count how many of each product were sold.
I mapped Product as a composite element of Invoice class.
How to write such query?
In pure SQL it would be as follows:
Code:
SELECT [ProductId], Sum([Amount]) as [AmountSold]
FROM [Invoices]
INNER JOIN [Products]
ON [Products].[InvoiceId] = [Invoices].[Id]
GROUP BY [ProductId];
And I think that it would be better for me to get not a mapped object but rather an Array or a list with that values. Is it possible? I am not sure, because CreateSQLQuery has a returnType parameter and according to documentation, it has to be a mapped class.
Is it possible to use sum function on elements function? If not, is it possible to write such query in HQL?
I use NHibernate 1.02 and MS SQL 2005.
Any help would be appreciated. Thanks in advance.
Regards,
snake_net