Group entity by entity

Posts   
 
    
Val
User
Posts: 37
Joined: 14-Nov-2008
# Posted on: 06-Feb-2009 16:40:41   

Is this scenario supported?

from c in meta.Customer
join o in meta.Order on c.CustomerID equals o.CustomerID
group o by c into g
select g;

I know that this can be accomplished in a different way but this is a simplification of a more complex expression that requires this kind of grouping.

Thanks,

Val

Val
User
Posts: 37
Joined: 14-Nov-2008
# Posted on: 06-Feb-2009 16:52:54   

Correction: this scenario doesn't work too.

from c in meta.Customer
join o in meta.Order on c.CustomerID equals o.CustomerID
group o by c[b].CustomerID[/b] into g
select g;

Neither this one:

from c in meta.Customer
join o in meta.Order on c.CustomerID equals o.CustomerID
group o.[b]OrderID[/b] by c[b].CustomerID[/b] into g
select g;

These work:

from c in meta.Customer
join o in meta.Order on c.CustomerID equals o.CustomerID
group o by c[b].CustomerID[/b] into g
select new { g.Key,Counter = g.Count()};

from c in meta.Customer
join o in meta.Order on c.CustomerID equals o.CustomerID
group o.[b]OrderID[/b] by c[b].CustomerID[/b] into g
select new { g.Key,Counter = g.Count()};

It seems whenever the select is made on the grouping variable without further calculations the expression throws exception.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 07-Feb-2009 04:49:28   

Yep. The _group _and the _select _ must be used on Fields or anonymous types ( new { ... } )

David Elizondo | LLBLGen Support Team
Val
User
Posts: 37
Joined: 14-Nov-2008
# Posted on: 07-Feb-2009 04:52:55   

No problem. In my scenario was easy to find a workaround.

Thank you.