I have a list of Diff objects Diff looks like this
public class Diff
{
ChangeAction Action // ChangeAction is an Enum
string Type
DateTime StartDateTime
DateTime EndDateTime
int rateId
string rateDescription
List<string> properties
DayOfWeek day
List<DaysOfWeek> DaysOfWeek
DayOfWeek DayOfWeek
}
My LINQ query does not do what I think it will do. I am passing in diff.properties
in the GroupBy()
, which is a List and I want it to group when all string values in a list match
var results = diffs
.GroupBy(diff => new { diff.properties, diff.Action, diff.Type, diff.StartDateTime,
diff.EndDateTime, diff.rateId, diff.rateDescription})
.Select(group => new Diff(
group.Key.Action,
group.Key.ScheduleType,
group.Key.StartDateTime,
group.Key.EndDateTime,
group.Key.rateId,
group.Key.rateDescription,
group.Key.properties,
group
.Select(ts => ts.DayOfWeek)
.Distinct()
.OrderBy(dow => dow)
.ToList()))
.ToList();
The only difference between results
and diffs
is that the singular DayOfWeek
that was previously stored in diffs
is now put into the plural DaysOfWeek
field (but just 1 item in the list). Currently, same # of items in both results
and diffs
.
What I'd like to see in the results list are:
- A shorter list that consolidates based on matching on all the grouping (including diff.properties list values)
- This would also mean more than 1 item in the DaysOfWeek list.
My question is:
How can I change my LINQ query above to see what I want to see in results
?