I am having trouble adding an orderby clause to this link query.
- var purchaseOrderData = await _context.PurchaseOrders
- .Where(s => s.SupplierNumber == "86087319")
- .GroupBy(o => new
- {
- SupplierNumber = o.SupplierNumber,
- SupplierName = o.Supplier.SupplierName,
- Month = o.OrderDate.Month,
- Year = o.OrderDate.Year
- })
- .Select(g => new
- {
- SupplierNumber = g.Key.SupplierNumber,
- SupplierName = g.Key.SupplierName,
- MonthOrd = g.Key.Month,
- Month = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(g.Key.Month),
- Year = g.Key.Year,
- Count = g.Count(),
- OrderAmount= g.Sum(o => o.OrderTotal)
- })
- .ToListAsync();
The above returns
[
{
"supplierNumber": "86087319",
"supplierName": "SUPPLIER 1",
"monthOrd": 2,
"month": "February",
"year": 2019,
"count": 5,
"orderAmount": 414402.86
},
{
"supplierNumber": "86087319",
"supplierName": "SUPPLIER 2",
"monthOrd": 3,
"month": "March",
"year": 2019,
"count": 19,
"orderAmount": 190563.24
},....]
I am trying to order this list by year and then month (number) by adding
.OrderBy(a => a.Year)
.ThenBy(a => a.Month)
before the .ToListAsync();
But the query returns an error indicating that the query cannot be translated.
Can you please help me add the orderby clauses to the above linq query?
Thanks for your help.
Asma KhalidPosted May 21, 2020, 10:57 PM
Asma KhalidPosted May 22, 2020, 12:02 AM
Michael SeeryPosted May 22, 2020, 12:01 AM
Asma KhalidPosted May 21, 2020, 11:55 PM
Michael SeeryPosted May 21, 2020, 11:53 PM
Asma KhalidPosted May 21, 2020, 11:48 PM
Michael SeeryPosted May 21, 2020, 11:45 PM
Michael SeeryPosted May 21, 2020, 11:38 PM
Michael SeeryPosted May 21, 2020, 11:37 PM
Asma KhalidPosted May 21, 2020, 11:28 PM
Michael SeeryPosted May 21, 2020, 11:25 PM
Asma KhalidPosted May 21, 2020, 11:21 PM
Michael SeeryPosted May 21, 2020, 11:15 PM
>>' does not contain a definition for 'OrderBy' and no accessible extension method 'OrderBy' accepting a first argument of type 'Task
>>' could be found (are you missing a using directive or an assembly reference?)