(I'm crossposing to users and dev because I _think_ this might be a new
feature idea)
I have the following model (not real):
class Sale { Product Product; int Quantity; }
Both Sale and Product are persistent entities.
I need a query to return sales by product, WITHOUT LOADING the products
(I'll just store the references somewhere else).
Now, if my query was "from Sale", I'd get proxies for Product references.
But I'm aggregating:
select s.Product, sum(s.Quantity)
from Sale s
group by 1
Of course this doesn't work, because the select gets the full Product, so
the group would have to include every property from Product (and it's not
what I want)
What I'm currently doing is:
select s.Product.id, sum(s.Quantity)
from Sale s
group by 1
And then I'm projecting the DTO to get the proxy:
query.List<object[]>()
.Select(x => new MyDTO
{
Product = session.Load<Product>(x[0]),
Total = Convert.ToInt32(x[1])
});
I couldn't think of a way to get proxies using plain HQL. If I could, I'd
just use an AliasToBeanResultTransformer.
Maybe we can add a new pseudo-function to HQL so it can be written as, for
example:
select reference(s.Product), sum(s.Quantity)
Thoughts?
Maybe it's easier than I thought and I'm just being stupid (a case of
Wednesdays?) It wouldn't be the first time.
Diego