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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:57:48+00:00 2026-06-09T23:57:48+00:00

I have a List collection that contains a List subcollection as a property within

  • 0

I have a List collection that contains a List subcollection as a property within it, and I want to filter out items in that subcollection based on the value of certain properties.

To simplify, I’ll call the main collection THING and the subcollection SUBTHING. They are different types. THINGS can have 1 to many SUBTHINGS. SUBTHING has 2 properties I want to filter by, PROP1 should equal 1 (it can equal 1,2,3) and PROP2 should not be NULL (it can contain a string).

So when I use a query like the one below it seems to give me what I want (though I’m not sure All() is doing what I expect):

search = from c in search
where c.SUBTHING.All(s=>s.PROP1==1)
select c;

Then I get suspicious when I add the other property:

search = from c in search
where c.SUBTHING.All(s=>s.PROP1==1 && s.PROP2 != NULL)
select c;

And I get THINGS that have PROP2 as Null.

When I switch to Any() I lose all filtering on SUBTHING and it shows SUBTHINGS where PROP1 = 1,2,3 and where PROP2 is NULL and not NULL.

What I’m trying to get is a collection that lists all THING IDs and then lists the Name of all SUBTHINGS, sort of like this:

THING.ID
     SUBTHING.Name
     SUBTHING.Name

THING.ID
     SUBTHING.Name
     SUBTHING.Name

Is this possible to also filter SUBTHINGS while filtering THINGS with LINQ since THING and SUBTHING are two different types?

  • 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-09T23:57:49+00:00Added an answer on June 9, 2026 at 11:57 pm

    Try something like this:

    search = 
        from c in search 
        where c.SUBTHING.All(s=>s.PROP1==1 && s.PROP2 != NULL) 
        select new {
             ThingId = c.ThingID,
             Something = c.SomeThing.Select(x=>x.Name)
         }; 
    

    To apply filter on subitems try:

    from product in products
    where product.productid == 1
    from image in product.productimages
    where image.ismainimage
    select image.imagename
    

    From : 101 linq queries

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a List<NameClass> that stores a collection of NameClass items with a property
I have a list view that displays a collection of items, each item has
I have a list box that contains a collection of documents that a user
I have a Dictionary<> collection that contains characters. The collection has items added and
I created a list<T> that contains a collection of objects that have this properties:
I have a list of items of a custom class. That class contains an
I have a a list of disposable items that I am adding to collection
I have a collection that contains a list of complex objects, SubCategory. SubCategory contains
I have two classes and want to build a collection that contains a collection.
I have a List Collection and say that i am adding 3 items to

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.