Can't get expression to work

Oct 29 2023 12:11 PM

Hi There,

I'm trying to show records in a grid in decending order. 
This is my schema:

[
  {
    "invoiceId": 1,
    "distributorId": 1,
    "invoiceDate": "2023-08-26T00:00:00",
    "invoicePaymentType": 3,
    "invoiceCost": 1023
  },
  {
    "invoiceId": 2,
    "distributorId": 1,
    "invoiceDate": "2023-09-04T00:00:00",
    "invoicePaymentType": 3,
    "invoiceCost": 4500
  }
]

And this is my code:
//Get individual Distributor Invoice
app.MapGet("/TYM/AllDistributorInvoices/{id}", async (TymContext context, int id) =>
{
    var distributorInvoices = await context.DistibutorInvoices
        .Where(d => d.DistributorId == id).ToListAsync();
       //distributorInvoices.OrderBy(e => e.InvoiceId);
       distributorInvoices.OrderByDescending(e => e.InvoiceId);
    return distributorInvoices;
});

What am I doing wrong.
it always returns invoice1, invoice2 when I want it to be invoice2, invoice1
Any help would be appreciated.
Best Regards,
Steve.


Answers (1)