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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:39:06+00:00 2026-05-14T08:39:06+00:00

I am looking for linq query to see if there exists a similar object

  • 0

I am looking for linq query to see if there exists a similar object

I have an object graph as follows

Cart myCart = new Cart
{
    List<CartProduct> myCartProduct = new List<CartProduct>
    {
        CartProduct cartProduct1 = new CartProduct
        {
            List<CartProductAttribute> a = new List<CartProductAttribute>
            {
                CartProductAttribute cpa1 = new CartProductAttribute{ title="red" },
                CartProductAttribute cpa2 = new CartProductAttribute{ title="small" }
            }
        }

        CartProduct cartProduct2 = new CartProduct
        {
            List<CartProductAttribute> d = new List<CartProductAttribute>
            {
                CartProductAttribute cpa3 = new CartProductAttribute{ title="john" },
                CartProductAttribute cpa4 = new CartProductAttribute{ title="mary" }
            }
        }

    }
}

I would like to get from the Cart => a CartProduct that has the exact same CartProductAttribute title values as a CartProduct that I need to compare.
No more and no less.

E.G. I need to find a similar CartProduct that has a CartProductAttribute with title=”red” and a cartProductAttribute with title=”small” in myCart (eg ‘cartProduct1’ in the example)

CartProduct cartProductToCompare = new CartProduct
{
    List<CartProductAttribute> cartProductToCompareAttributes = new List<CartProductAttribute>
    {
        CartProductAttribute cpa5 = new CartProductAttribute{ title="red" },
        CartProductAttribute cpa6 = new CartProductAttribute{ title="small" }
    }
}

So from object graph

  • myCart
    • cartProduct1
      • cpa1 (title=red)
      • cpa2 (title=small)
    • cartProduct2
      • cpa3 (title=john)
      • cpa4 (title=mary)

Linq query looking for

  • cartProductToCompare
    • cpa5 (title=red)
    • cpa6 (title=small)

Should find

  • cartProduct1

Hope all this makes sense…

Thanks

  • 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-14T08:39:07+00:00Added an answer on May 14, 2026 at 8:39 am

    I think this is what you are after.

    var attributes = new [] { "red", "small" };
    var result = myCart.Products.Where(product => 
        product.Attributes.All(attribute => 
            attributes.Contains(attribute.title)
        )
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

LINQ gurus, I am looking for help to write a query... I have a
Hi I am looking for best method for writing Dynamic LINQ query. I have
Looking for linq query to fill a list with month + year for example
Is there a way to have a single LINQ Query that contains two different
I'm looking into LINQ and the query language appears (at least on the surface)
I have just been looking into Linq with ASP.Net. It is very neat indeed.
I just looking how to use LINQ for grouping a list. Class Item Public
i am looking for some input for how to use linq with javascript, there
I'm looking at implementing some LINQ to SQL but am struggling to see how
I am looking to optimize my LINQ query because although it works right, the

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.