0

For my issue, I have a list of objects (Producers).

For each producer record, there are some properties (ID, DisplayName, and StateCode).

There can be multiple items in the list that have the same ID & DisplayName, but different StateCodes.

I am having trouble querying this to give me a distinct list of Producers with each of their possible StateCodes in a new object.

I would prefer to have the new objects to have the ID, DisplayName, and a List which contains each StateCode of theirs.

Can someone point out the proper way I could create this new list?

0

1 Answer 1

1

you're looking for LINQ's GroupBy:

var groups = producerList.GroupBy(p => new { p.ID, p.DisplayName });

group on the 2 properties, then your groups' values will be an IEnumerable of StateCodes

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.