Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7889959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:13:51+00:00 2026-06-03T06:13:51+00:00

I have a Lookup that has a master list of priority levels and groups.

  • 0

I have a Lookup that has a master list of priority levels and groups. Also, a List that has the groups an user is in. ILookup<int, string>, List<string>. I’d like to compare the List to ILookup and return the IGroupings that match the groups in the List. Then finally get the IGrouping with the higher priority (ex: returns 6 instead 3).

My issue is with the actual comparision of the List and ILookup. It seems I might have to use a for-loop. But I think I just haven’t found the right Linq statement(s) yet.

What I’ve tried below.

        List<string> groupsOfUser = whatGroupsUserBelongTo();
        ILookup<int, string> loginGroups = mapADToRole.SelectMany(ad => ad.Value
                                                                          .Select(grp => new {ad.Key, Value = grp}))
                                                      .ToLookup(adLkUp => adLkUp.Key, adLkUp => adLkUp.Value);


        var blah = loginGroups.Where(adGrp => adGrp.SelectMany(ad => groupsOfUser.Contains(ad)));

UPDATE:

mapADToRole is Dictionary<int, List<string>>. The code below works but using foreach loops.

        public static string getWindowsGroup()
        {
            List<string> groupsOfUser = whatGroupsUserBelongTo();
            ILookup<int, string> loginGroups = mapADToRole.SelectMany(ad => ad.Value
                                                                              .Select(grp => new {ad.Key, Value = grp}))
                                                          .ToLookup(adLkUp => adLkUp.Key, adLkUp => adLkUp.Value);



            List<IGrouping<int, string>> foo = new List<IGrouping<int, string>>();
            foreach (IGrouping<int, string> loginGroup in loginGroups)
            {
                foreach (var blah in loginGroup)
                {
                    if (groupsOfUser.Contains(blah))
                    {
                        foo.Add(loginGroup);
                    }
                }
            }

            var foobar = foo.Max(grp => grp.Key);
            return loginGroups[foobar].FirstOrDefault();

        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T06:13:53+00:00Added an answer on June 3, 2026 at 6:13 am

    I am not sure but this should do what your function does:

    return mapADToRole.Where(item => item.Value.Any(groupsOfUser.Contains))
                      .OrderBy(item => item.Key)
                      .SelectMany(item => item.Value)
                      .FirstOrDefault();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Dictionary that has a signature: Dictionary<int, List<string>> . I'd like to
I have a Dictionary<string,int> that has the potential to contain upwards of 10+ million
I have a small tab on an app that allows user to lookup a
I have a lookup table that has a Name and an ID in it.
i have an orders table that has a userID column i have a user
I have a class MyClass that has a static variable. Class implements smth like
I have a list in Sharepoint that has 2 columns. "Name" and "Surname". Then
Assume I have a class SomeClass that has a lookup dictionary: DataDictionary; I currently
I have a content type that has a lookup field for a document library
I have a list of strings (a List<String> ) that can have anywhere from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.