0

I am using LINQ and doing a group by using multiple objects. One of these objects is a HashSet.

var group = map.GroupBy(m => new{m.Item2.Clients,m.Item3,m.Item2.StartTimeID});

Where m.Item2.ClientCampaigns is of type HashSet, m.Item3 is a seperate class that methods for GetHashCode and Equals methods m.Item2.StartTimeId is of type INT

Now I need to do a GROUP BY on these three, by passing in a custom IEquality Comparer I guess?

If it was just HasSet, I could use HashSet<ClientCampaign>.CreateSetComparer() as the second argument in the GroupBy method.

In this case, what should I use?

svick
  • 236,525
  • 50
  • 385
  • 514
ManJan
  • 3,939
  • 3
  • 20
  • 22
  • If you can get the member Item2 for multiple instance to point to the exact same instance of ClientCampaigns, then this would work the way you have it. You may need to do the same for the Item 3 member. Objects will be deemed "equal" if they are references to the exact same instance. – Mike Hixson Jun 16 '14 at 04:18

1 Answers1

0

I solved it! I created a new class with all the parameters, I am grouping by. I have created a new custom Comparer that extends from IEqualityComparer. This custom comparer must have public bool Equals and public int GetHashCode methods respectively. And, Then I used this Comparer in the GroupBy clause I have in the code.

ManJan
  • 3,939
  • 3
  • 20
  • 22