Hierarchical group by

3 posts, 1 answers
  1. Bernd
    Bernd avatar
    53 posts
    Member since:
    Feb 2013

    Posted 16 Jun Link to this post

    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. Answer
    Viktor Zhivkov
    Admin
    Viktor Zhivkov avatar
    291 posts

    Posted 21 Jun Link to this post

    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.
  3. DevCraft banner
  4. Bernd
    Bernd avatar
    53 posts
    Member since:
    Feb 2013

    Posted 21 Jun in reply to Viktor Zhivkov Link to this post

    Hello Viktor.

    That did the trick. Thank you.

    Regards

    Bernd

Back to Top