So, I have some data, which comes like this:
[
{
"Name": "Jonh ",
"Order": [
{
"Product": {
"Id": 8
},
"Quantity": 1
},
{
"Product": {
"Id": 19
},
"Quantity": 8
}
]
},
{
"Name": "Jane Doe 1",
"Order": [
{
"Product": {
"Id": 26
},
"Quantity": 7
},
{
"Product": {
"Id": 44
},
"Quantity": 2
},
{
"Product": {
"Id": 21
},
"Quantity": 6
},
{
"Product": {
"Id": 48
},
"Quantity": 2
},
{
"Product": {
"Id": 35
},
"Quantity": 2
},
{
"Product": {
"Id": 43
},
"Quantity": 1
}
]
}
]
UPDATE: the JSON is already parsed with NewtonSoft.Json.JsonConvert
I am completely new to Linq, i was able to do this in JavaScript.
I need a linq query that extracts the sold products ordered by the most sold;
so: it aggregates every product and sums the quantity sold, and orders by the sum of the quantities.
This is what i have for now:
var products = clientSales.SelectMany(m => m.Order).Select(f=>f.Product.Id).Distinct();
which gives me a list of distinct productIds...