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 3605782
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:10:00+00:00 2026-05-18T21:10:00+00:00

Teaching myself some c# and my problem is that I have a class which

  • 0

Teaching myself some c# and my problem is that I have a class which creates Person objects and adds them to a List (myPersonList). I also have a PartyGroup class which takes a PersonList as one of its properties. My issue is that myPersonList contains the whole results set so at the moment each time it creates a new PartyGroup it adds all the values in myPersonList. Is there a way to tell it to only add those values in myPersonList where the Person.PartyGroupId matches the current PartyGroup groupID we are dealing with. Hope that makes sense. Thanks.

//Person

using (AseDataReader reader = commandPerson.ExecuteReader())

        {
            while (reader.Read())
            {
                Person person = new Person();
                person.PersonID = Convert.ToInt32(reader["person_id"]);
                person.PartyGroupID = Convert.ToInt32(reader["party_group_id"]);
                person.FullName = reader["full_name"].ToString();

                myPersonList.Add(person);
            }
        }

//PartyGroup

using (AseDataReader reader = commandPartyGroup.ExecuteReader())

        {
            while (reader.Read())
            {
                int groupId = Convert.ToInt32(reader["party_group_id"]);

                if (myPartyGroupList.Where(partyGroup => partyGroup.PartyGroupID == groupId).Any() == false) 
                {
                    PartyGroup partyGroup = new PartyGroup()
                    {
                        PartyGroupID = groupId,
                        PartyGroupName = reader["party_group_name"].ToString(),
                        PersonList = myPersonList//where PersonList objects contain this groupId???


                    };

                    myPartyGroupList.Add(partyGroup);

                }

            }

        }
  • 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-05-18T21:10:01+00:00Added an answer on May 18, 2026 at 9:10 pm

    If I understand your problem correctly, you just need:

    PersonList = myPersonList.Where(p => p.PartyGroupID == groupId).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am teaching myself some Python and I have come across a problem which
I'm teaching myself some basic scraping and I've found that sometimes the URL's that
I'm teaching myself VB.Net. Here is a problem I have recently come across. Say
I'm teaching myself Python and my most recent lesson was that Python is not
I have been teaching myself JS and Jquery primarily for GM scripts (im not
I'm teaching myself Objective-C as a guilty pleasure, if you would. I have a
I am teaching myself some Javascript and don't understand why Chrome console tells me
I'm teaching myself Scala and I have sort of a philosophical question. Is pattern
I'm teaching myself CSS and HTML, and I've come across something that seems like
So, I'm working on teaching myself jQuery with the help of some books, and

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.