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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:28:22+00:00 2026-05-11T18:28:22+00:00

I am having trouble efficiently selecting the information I need to display. Hopefully someone

  • 0

I am having trouble efficiently selecting the information I need to display. Hopefully someone else has a better idea of how to solve this.

Given the following data structures,

public class Department
{
   public int ID { get; set; }
   public string Name { get; set; }
   public IList<Product> Products{ get; set; }
}

public class Product
{
   public int ID { get; set; }
   public string Name { get; set; }
}

And given the following data

Department1 = 
{
    Id=1,
    Name="D1",
    Products = {new Product{Id=1, Name="Item1"}, new Product{Id=2, Name="Item2"}
}

Department2 = 
{
    Id=2,
    Name="D2",
    Products = {new Product{Id=2, Name="Item2"}, new Product{Id=3, Name="Item3"}
}

How do I select out that “Item2” is common to both “D1” and “D2”?

I have tried using an intersection query, but it appears to want two deferred query execution plans to intersect rather than two IEnumerable lists or ILists.

Any help with this is greatly appreciated.

Edit: It appears I wasn’t very precise by trying to keep things simple.

I have a list of departments, each contain a list of products. Given these lists, how do I select another list of products based on a particular criteria. My criteria in this instance is that I want to select only products that exist in all of my departments. I want only the data that intersects all elements.

  • 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-11T18:28:22+00:00Added an answer on May 11, 2026 at 6:28 pm

    My Intersect function works fine:

            Department department1 = new Department
            {
                Id = 1,
                Name = "D1",
                Products = new List<Product> () { new Product { Id = 1, Name = "Item1" }, new Product { Id = 2, Name = "Item2" } }
            };
    
            Department department2 = new Department
            {
                Id = 2,
                Name = "D2",
                Products = new List<Product>() { new Product { Id = 2, Name = "Item2" }, new Product { Id = 3, Name = "Item3" } }
            };
    
            IEnumerable<Product> products = department1.Products.Intersect(department2.Products, new ProductComparer());
    
            foreach (var p in products)
            {
                Console.WriteLine(p.Name);
            }
    

    (edit)

        public class ProductComparer : IEqualityComparer<Product>
        {
            public bool Equals(Product x, Product y)
            {
                return x.Name == y.Name && x.Id == y.Id;
            }
    
            public int GetHashCode(Product obj)
            {
                return obj.Id.GetHashCode() ^ obj.Name.GetHashCode();
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble looking for information in this topic, when it's more efficient to
Having trouble finding an explanation in the docs, would someone be kind enough to
Having trouble with recursive methods in c#. When compiled it should just display the
Having trouble with a mysql grant statement. I want a user who has: readonly
I`m having trouble trying to optimize this query with OVER (PARTITION BY ...) because
I'm having trouble efficiently loading data into a sparse matrix format in R. Here
I am having trouble and need some help finding a correct SQL query. Here
I am having trouble implementing a python algorithm which does the following: (This is
I am having trouble understanding how I can effectively and efficiently building a mocking
I'm having trouble coming up with a working query for this situation... Table: [

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.