© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
6 replies
SWEETPONY

✅ how to remove duplicates?

I have the following method for preparing a dataset. The problem is that I receive territory ids and use them to group and form the dataset. For some reason, if multiple ids are passed at once and the data has something in common, it gets duplicated: accessGroup.Id, accessGroup.Title, accessGroup.Description. Please help me understand where the mistake is.

group:
var groupedAccessGroups = accessGroups
    .SelectMany(accessGroup => accessGroup.Compositions,
        (accessGroup, compositions) => (
            accessGroup.Id,
            accessGroup.Title,
            accessGroup.Description,
             Compositions: compositions
        ))                                                                                                     
    .Where( accessGroup => territoriesIDs.Contains( accessGroup.Compositions.TerritoryId ) )
    .GroupBy( accessGroup => accessGroup.Compositions.TerritoryId );
var groupedAccessGroups = accessGroups
    .SelectMany(accessGroup => accessGroup.Compositions,
        (accessGroup, compositions) => (
            accessGroup.Id,
            accessGroup.Title,
            accessGroup.Description,
             Compositions: compositions
        ))                                                                                                     
    .Where( accessGroup => territoriesIDs.Contains( accessGroup.Compositions.TerritoryId ) )
    .GroupBy( accessGroup => accessGroup.Compositions.TerritoryId );
9030fed80203f612.png
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ how remove duplicates from string?
C#CC# / help
3y ago
✅ How to select duplicates on VS
C#CC# / help
3y ago
LInq Combine duplicates
C#CC# / help
3y ago
MAUI. How to remove the Title Bar?
C#CC# / help
2y ago