I am trying to get a set of records that match certain criteria. Imagine I have a list of orders, each with a nested account, a bit like this:
var orders = [{
account: {
id: 1
}
}, {
account: {
id: 1
}
}, {
account: {
id: 2
}
}, {
account: {
id: 2
}
}, {
account: {
id: 1
}
}, {
account: {
id: 4
}
}, {
account: {
id: 3
}
}];
I would like to use LINQ to get all the distinct accounts based on the account id. I thought I might be able to do something like:
var accounts = results.Select(m => m.Account).GroupBy(m => m.AccountNumber).Distinct();
but that doesn't appear to work. Can someone help me out?