Having the below:
Methods = dbExpenses
.SelectMany(e => e.UserExpenses, (expense, ue) => new { expense, ue })
.GroupBy(e => new { e.ue.Method, e.ue.UserId })
.Select(x => new GetInsightsByMethodDto {
Method = x.First().ue.Method.ToString(),
Frequency = x.Count()
}).ToList()
I have successfully grouped the result by both Method and UserId and the response is correct as such:
"methods": [
{
"method": "Cash",
"frequency": 1
},
{
"method": "Cash",
"frequency": 2
},
{
"method": "Transfer",
"frequency": 1
}
]
User one has used both Card and Transfer with the frequency of 1 for each. However user two has used Cash with a frequency of 2. So as you can tell, the first object in the array is for user one as well as the last item. However, the second item is for user two.
The desired output however is the below:
"methods": [{
"method": "Cash",
"frequency": 1
},
{
"method": "Transfer",
"frequency": 1
}
], [{
"method": "Cash",
"frequency": 2
}]
Which consists of a second array for the other user.
What am I missing here? Thanks in advance for the help!