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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:55:58+00:00 2026-06-17T03:55:58+00:00

I have two tables, each with their own model… class FamilyMan { public int

  • 0

I have two tables, each with their own model…

    class FamilyMan
    { 
        public int family_ID {get; set;}

        public string name {get; set;}
        public string fav_color {get; set;}
    }

    class BusinessMan
    {
        public int work_ID {get; set;}

        public string name {get; set;}
        public string fav_color {get; set;}

        //unrelated data etc
        public string job_title {get; set;}
    }

… and I want to be able to match up all FamilyMans to the matching BusinessMans based on name and fav_color.

I currently have something like:

    //fill lists from database
    var family_list = dbContext.FamilyMen.ToList();
    var busy_list = dbContext.BusinessMen.ToList();
    //create empty dict for matching the two types
    var matches = new Dict<FamilyMan, BusinessMan>();


    foreach (FamilyMan fam_man in family_list) {
        foreach (BusinessMan busy_man in busy_list) {
            //if both names and colors match, consider them a matching
            //object and add them each to the dict
            if (fam_man.name == busy_man.name &&
                    fam_man.color == busy_man.color) {
                matches_MtO[fam_man] = busy_man;
            }
        }
    }

but it takes quite a time to complete.

I’ve also looked at looping over one list with a foreach and then using LINQs FirstOrDefault to match them, but the efficiency seems about the same.

Is there a better way to go about matching FamilyMans and BusinessMans together?

  • 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-17T03:55:59+00:00Added an answer on June 17, 2026 at 3:55 am

    You should use LINQ’s join syntax. This will enable the backend database to do the matching, and return only the result.

    In order to enable a join on a composite key, follow the MSDN guidance here.

    var query = from fm in dbContext.FamilyMen
                join bm in dbContext.BusinessMen on 
                    new { bm.name, bm.color } equals new { fm.name, fm.color }
                select new {
                   FamilyMan = fm,
                   BusinessMan = bm
                };
    
    var resultList = query.ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Retrieving the last record in each group I have two tables set
I have two separate integration test files, each with their own context configuration files
I have two queries that each, on their own, run pretty quickly (less than
Consider two tables transaction and category each having their own ID and information. A
I have a problem with mutual constraints. I want to have two tables each
I have two tables table1 and table2 each having a column named email along
i have two tables products and reviews each product has several reviews linked by
I have two tables: Folder, Files. Each table has 4 fields: ParentID, ID, Name,
I have a table with two child tables. For each record in the parent
I have two datagrids side by side bound to different data tables and each

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.