Reputation: 1575
I need to do a select distinct where I compare 2 values. In the method I do the following:
DistinctErrors = Errors.Select(o => new { o.Type, o.References })
.Distinct()
.Count();
o.Type is a string, but o.References is a Collection of objects. Each object in o.References has a Name property as string and a Value Property as string, and it's actually o.Type and each o.Reference's Name and Value values I want to compare, so it's actually 3 values to compare.
How can I compare Type with each Reference Name and Value?
Thanks, Peter
Upvotes: 2
Views: 946
Reputation: 152566
Perhaps you want to flatten the references using SelectMany
?
DistinctErrors = Errors.SelectMany(o => o.References, (o, r) => new {o.Type, r.Name, r.Value})
.Distinct()
.Count();
Upvotes: 1