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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:29:20+00:00 2026-06-08T19:29:20+00:00

I used to ask a similar question which was aiming to understand how to

  • 0

I used to ask a similar question which was aiming to understand how to get the models at the other set which are having the same property with the one I am holding.

Now the problem is:
So, what was the name of the “similar property” which actually guided me to the other set.

The original post was:
C# LINQ to Entities query for the intersection of two different properties

I have 3 models named:

  1. Pencil having Pencil.Id(int) and Pencil.Colors(IEnumerable) Property
  2. Pen having Pen.Id(int) and Pen.Colors(IEnumerable) Property
  3. Colors having Id and name.

Colors model is IEnumerable so it has more than 1 color. For example; the pen has 15 different colors and pencil is having 25 different colors. I want to bring the corresonding pencil if one of the colors of the pen that I am holding is also avaialable in the color palette of that pencil.

Raphael‘s great solution is https://stackoverflow.com/a/11722191/1062284

int id = id_of_the_pen_that_i_am_holding;
Pen p = db.Pens.Find(id);
var penColorIds = p.Color.Select(m => m.Id).ToList();
var list = db.Pencils.Where(pencil => pencil.Color.Any(color => penColorIds.Contains(color.Id));

So it is OK and working like a charm but how about learning the name of the common colors?
We get the other properties which are holding the same color but what was that color?

I will appreciate if some one can produce this LINQ query. I am pretty new for LINQ and will much appreciate any help.

  • 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-08T19:29:23+00:00Added an answer on June 8, 2026 at 7:29 pm

    If you are holding multiple pens in your hand then use (in variable pens)

    var colors = pens.SelectMany(p=>p.Colors).Distinct(); 
    var commonColors = db.Pencils.SelectMany (p => p.Colors.Where(c=>colors.Contains(c))).Distinct()
    

    Else if you only have one pen (in variable pen)

    var colors = pen.Colors;
    var commonColors = db.Pencils.SelectMany (p => p.Colors.Where(c=>colors.Contains(c))).Distinct()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Simple question. A friend of mind wrote code similar to this one (which is
I ask a similar question here . This is My Model: [DisplayName(National Code)] [Required(ErrorMessage
I have asked a similar question elsewhere but perhaps I did not ask it
I would like to ask which controls can be used to create a design
I thought to ask this as an update to my previous similar question but
I havent used lucene. Last time i ask (many months ago, maybe a year)
Having used storyboards for a while now I have found them extremely useful however,
I've seen a couple similar threads to this question, but none of them really
This is a follow up to my question earlier here: Android: Autocomplete TextView Similar
I've modified my original question (hope that's allowed)... I have used WCF to expose

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.