This is a migrated thread and some comments may be shown as answers.

Hierarchical group by

2 Answers 53 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Bernd
Top achievements
Rank 2
Bernd asked on 16 Jun 2016, 01:02 PM

Hello all.

The following LINQ statement tells me:

"Execution of 'System.Linq.Enumerable:GroupBy(IEnumerable`1,Func`2)' on the database server side currently not implemented. This occured from g1.GroupBy(o => o.SequenceNumber)"

1.var ops = _db.Operations.Where(o => !filteredStates.Contains(o.ProcessingStatus) && o.CalendarEvents.Count == 0 && o.WorkOrder.QuantityToProduce - o.QuantityConfirmed > 0)
2.    .GroupBy(o => new { o.WorkOrderId }).Select(g1 => new {
3.        g1.Key,
4.        Operations = g1.GroupBy(o => o.SequenceNumber).Select(g2 => g2)
5.    }).ToList();

Any ideas how to work around such a situation?

Kind regards

Bernd

2 Answers, 1 is accepted

Sort by
0
Accepted
Viktor Zhivkov
Telerik team
answered on 21 Jun 2016, 02:46 PM
Hello Bernd,

I believe you can safely split the query into database and in-memory parts while keeping the same behavior and performance. Adding an extra .ToList() call after the first .GroupBy() should do the job:
1.var ops = _db.Operations.Where(o => !filteredStates.Contains(o.ProcessingStatus) && o.CalendarEvents.Count == 0 && o.WorkOrder.QuantityToProduce - o.QuantityConfirmed > 0)
2.    .GroupBy(o => new { o.WorkOrderId })
3.    .ToList();
4.var groupedOps = ops.Select(g1 => new {
5.        g1.Key,
6.        Operations = g1.GroupBy(o => o.SequenceNumber).Select(g2 => g2)
7.    }).ToList();

If you can not apply this work around in your particular scenario, please let us know and give us the details that are preventing you from utilizing the outlined approach

Regards,
Viktor Zhivkov
Telerik
 
Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
0
Bernd
Top achievements
Rank 2
answered on 21 Jun 2016, 03:11 PM

Hello Viktor.

That did the trick. Thank you.

Regards

Bernd

Tags
LINQ (LINQ specific questions)
Asked by
Bernd
Top achievements
Rank 2
Answers by
Viktor Zhivkov
Telerik team
Bernd
Top achievements
Rank 2
Share this question
or