I tried, but I couldn't get it to eager-load the customer when it's part of
a group-by either.
The best I could come up with was adding a second query:
s.QueryOver<Customer>()
.Where(c => c.Id.IsIn(_list.Select(l => l.Client.Id).ToList()))
.List();
... which reduces it from N+1 to 2.
On 15 April 2012 08:47, Oskar Berggren <[email protected]> wrote:
> Maybe someone knows a better way to express the query. One way to
> mitigate the effect of the current query would be to define batch-size
> in the mapping for Customer. This is probably a good idea anyway, and
> will turn your N+1 into e.g. N+1/20.
>
> /Oskar
>
>
> Den 15 april 2012 07:41 skrev WillyA <[email protected]>:
> > Hi,
> > First i'm a beginner with the QueryOver
> > I have some problems to specifiy eager fetch mode with QueryOver
> > group.
> > I have two class (Northwind samples)
> > - Customer
> > - Order with a many-to-one association with Customer
> > and OrderCustomerSummary as DTO
> > public class OrderCustomerSummary
> > {
> > public Customer Client { get; set; }
> > public decimal Total { get; set; }
> > public Int64 Nb { get; set; }
> > }
> > I want to query Order with Customer group by , with count(..) and
> > sum(...) and use AliasToBean mechanism to put in an
> > IList<OrderCustomerSummary> like this.:
> > ....
> > OrderCustomerSummary _customerSummary=null;
> > IList<OrderCustomerSummary> _list =
> > mSession.QueryOver<Order>()
> > .Fetch(pO => pO.Customer).Eager
> > .SelectList(pList => pList
> > .SelectGroup(pO =>
> > pO.Customer).WithAlias(()=> _customerSummary.Client )
> > .SelectSum(pO =>
> > pO.Freight).WithAlias(() => _customerSummary.Total)
> >
> .SelectCount(pO=>pO.Freight).WithAlias(()
> > => _customerSummary.Nb)
> > )
> >
> .TransformUsing(Transformers.AliasToBean<OrderCustomerSummary>())
> > .List<OrderCustomerSummary>();
> > ...
> > And when I iterate thru the results , i get N+1 Select problem, even i
> > specify eager fetch for "Customer".
> > Is there another way to do it to make eager fetch to work ?
> > Thanks for any help.
> > Willy
> >
> > --
> > 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.
> >
>
> --
> 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.
>
>
--
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.