There's no SELECT+1 because those proxies will never be initialized.
Assume what comes next is:
foreach (var dto in results)
session.Save(new SalesReport { Product = dto.Product, Total = dto.Total,
Date = DateTime.Today });
(Of course in this sample I _could_ create the proxies just for saving, but
the real code is, of course, persistance-ignorant and I'd rather just pass
the SalesReport to the DAO)
So, getting initialized Products is not needed here. What I was aiming for
was just a cleaner way to get my uninitialized proxies using HQL.
This would be the equivalent Criteria:
session.CreateCriteria<Sale>()
.SetProjection(Projections.ProjectionList()
.Add(Projections.GroupProperty("Product"), "Product")
.Add(Projections.Sum("Quantity"), "Total"))
.SetResultTransformer(Transformers.AliasToBean<DTO>())
.List<DTO>();
Which works fine, but is awfully verbose.
Diego
On Wed, Sep 29, 2010 at 12:52, Fabio Maulo <[email protected]> wrote:
> 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]<nhusers%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>
--
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.