I have a DTO called FileRecordDto, with a property that is a dictionary of strings. This dictionary represents one transaction record. Values are all strings and the Keys are column names:
public class FileRecordDto
{
public IDictionary<string, string> Fields { get; internal set; }
= new Dictionary<string, string>();
}
I also have an enum wrapper class to represent the column names
public class FieldName
{
public enum CRFS
{
Amount,
ActionDate,
ContractReference,
CycleDate,
}
}
Given an input list of FileRecordDtos, I need to group by unique records based on four fields. I've found a standard approach on StackOverflow to handle this, but it seems to break when checking against an array of strings:
var filteredRecords = originalRecords.GroupBy(x => new string[]
{
x.Fields[nameof(FieldName.CRFS.ContractReference)],
x.Fields[nameof(FieldName.CRFS.ActionDate)],
x.Fields[nameof(FieldName.CRFS.Amount)],
x.Fields[nameof(FieldName.CRFS.CycleDate)]
});
return filteredRecords.Select(y => y.First()).ToList();
IntelliSense inspection during run-time shows that the string arrays for two different records may look the same, but they are treated as different values.
What am I doing wrong?