Last post Aug 15, 2019 08:22 PM by DA924
Aug 15, 2019 05:45 PM|lesponce|LINK
I got this single line of code: viewModel.MyOrders.AddRange(responseModel.Data.Select(orders => orders));
I receive all the orders. If there are more than one row for the same order, I'd like to select the first one. That way I don't get something like this:
Instead, I need to get something like this:
Aug 15, 2019 06:19 PM|yogyogi|LINK
You need to apply the group by clause https://docs.microsoft.com/en-us/dotnet/csharp/linq/group-query-results
Aug 15, 2019 06:21 PM|DA924|LINK
Aug 15, 2019 06:32 PM|lesponce|LINK
I tried this, but do I need to add the name of the order field?
viewModel.MyOrders.AddRange(responseModel.Data.Select(orders => orders).Distinct());
How the query will identify that I need distinct order number, even if I have different States within the data?
Aug 15, 2019 07:31 PM|mgebhard|LINK
One more column is required either an identity or sort. Otherwise, 2222 can be VA or FL.
Aug 15, 2019 07:51 PM|lesponce|LINK
right, which is good. How do you recommend fixing this?
Aug 15, 2019 08:00 PM|bruce (sqlwork.com)|LINK
if you group by orderid (or whatever the key is), then you will get a grip for each order and in this group you will get a collection of the dups. you then need to summarize this collection to one row, say using first(), or summations.
var orders = response.Model.Data.GroupBy
r => r.OrderIdId,
r => r,
(key, g) => g.First()
Aug 15, 2019 08:06 PM|lesponce|LINK
Thanks for your help!
Aug 15, 2019 08:22 PM|DA924|LINK