zzzprojects / System.Linq.Dynamic.Core

The .NET Standard / .NET Core version from the System Linq Dynamic functionality.
https://dynamic-linq.net/
Apache License 2.0
1.57k stars 228 forks source link

I'm using OrderBy together with GroupByMany, but my elements does not get ordered correctly. #815

Closed LAKN-Lasse-Knudsen closed 4 months ago

LAKN-Lasse-Knudsen commented 4 months ago

Here is what to include in your request to make sure we implement a solution as quickly as possible.

1. Description

I'm using OrderBy together with GroupByMany, but my elements does not get ordered correctly. When I print out the elements in each subGroup the Dates are NOT sorted, but jumping around.

var sel = invoiceLines.AsQueryable().**OrderBy**("BusinessUnitId", "CustomerId", "DeliveryAddressId", "Date").**GroupByMany**("BusinessUnitId", "CustomerId", "DeliveryAddressId", "Date").ToList();

foreach (var group in sel)
            {
                Traverse(group, 0);
            }
----
Traverse(GroupResult group, int indent)
        {
            if (group.Subgroups != null)
            {
                foreach (var subgroup in group.Subgroups)
                {
                    Traverse(subgroup, indent + 2);
                }
            }

            foreach (var value in group.Items)
            {
                var invoiceLine = value as InvoiceLineDB; // Replace InvoiceLine with your actual type
                if (invoiceLine != null)
                {
                    System.Diagnostics.Debug.WriteLine($"{new string(' ', indent)} BusinessUnitId: {invoiceLine.BusinessUnitId}, CustomerId: {invoiceLine.CustomerId}, DeliveryAddressId: {invoiceLine.DeliveryAddressId}, Date: {invoiceLine.Date}, {invoiceLine.Description}"); // Replace with your actual logic
                }
            }
        }