in practice
var yourDto = s.CreateQuery("select p.id, sum(s.Quantity) from Sale s
join s.Product p group by p.id").Future<object[]>().Select(...);
var products = s.CreateQuery("select p from Sale s join s.Product
p").Future<Product>();
should do the trick

On Wed, Sep 29, 2010 at 12:48 PM, Fabio Maulo <[email protected]> wrote:

> After that query what you will do ?
> Are you looking for SELECT-N+1 or you have some other setting ?
>
> On Wed, Sep 29, 2010 at 12:26 PM, Diego Mijelshon 
> <[email protected]>wrote:
>
>> (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
>>
>
>
>
> --
> Fabio Maulo
>
>


-- 
Fabio Maulo

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to