Last post Jul 09, 2019 08:35 AM by gio2387
Jul 05, 2019 01:10 PM|webdeveloper2016|LINK
I have the following LINQ query that essentially should group all comments that match a certain product id and store in a dictionary.
var adjustments = context.adjustments.Where(m => m.adjustment_week_number == WeekNumber && m.adjustment_year == Year && m.dispatch_site_id == DispatchSiteID && m.incinerator_id == IncineratorID).GroupBy(m => m.product_component_id).ToDictionary(x => x.Key,
x => x.Select(m => m.adjustment_comments)).Distinct().ToList();
What I then want to do is to display all comments relating to each product id (there could be several different comments in each case) to screen but cannot figure out how to do this. I have tried the following, which does display the id but for the comments
field I get the error: System.Linq.Enumerable+WhereSelectEnumerableIterator.
What am I doing wrong please?
Jul 08, 2019 07:13 AM|Yuki Tao|LINK
According to your descriptions,I suggest you need to keep in mind your
Because there are something wrong during the iteration.
string.Join function can't know what do you wan to iteration in adjustments which is a dictionary type with Key and Value.
So,I suggest you could add wrap the loop outside the function,for example:
foreach (var res in adjustments )
MyStringBuilder.Append(res.Key + " : " + string.Join("#", res.Value.Select(x => x))+";");
the output in my project:
Jul 09, 2019 08:35 AM|gio2387|LINK
Yes, that's true! I think your solution should be fine.