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

  • Home
  • SEARCH
  • 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 6916405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:35:55+00:00 2026-05-27T09:35:55+00:00

I have a collection that contains a collection of attributes. Each attribute has a

  • 0

I have a collection that contains a collection of attributes. Each attribute has a type and an Id. I need to filter the collection where the attribute ids are or’d within a group of attribute types but the attribute types are and’d. I came up with the following and wonder if there is a better way.

foreach (var ag in andAttrGrpIds)
{
  filteredModels = filteredModels.Where(x => x.ProductAttributes.Any(pa => pa.AttributeType==ag && orAttributes.Contains(pa.AttributeId))).ToList();            
}

In the above snippet, andAttrGrpIds and orAttributes are arrays of string.

  • 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-27T09:35:56+00:00Added an answer on May 27, 2026 at 9:35 am

    I would do:

    var filteredModels = from model in originalModels
    
                         let mAttribs = from pa in model.ProductAttributes
                                        where orAttributes.Contains(pa.AttributeId)
                                        select pa.AttributeType
    
                         where !andAttrGrpIds.Except(mAttribs).Any()
    
                         select model;
    

    Now that’s more readable and (probably) has a better performance profile.

    The idea is to get the set of all ‘qualifying’ product attribute-types from each model and then test if all the andAttrGrpIds are present in this set.

    By the way, your naming conventions seem quite strange: The andAttrGrpIds collection appears to actually represent a collection of attribute-types.

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

Sidebar

Related Questions

I have a collection that contains user objects, each with a unique ID and
In PHP, I have a product object that contains a collection of attributes. json_encode
I have a List collection that contains a List subcollection as a property within
I have a MongoDB (v2.2.0) collection that contains reference data. Periodically, I need to
I have a collection that contains all the items that I want to keep
I have a REST service that returns a collection that contains non- normalized data.
Suppose I have a solution inside a TFS collection that contains 3 projects. Ho
Suppose I have a Collection of some kind that itself contains Collections; e.g., Dictionary(Of
I have an entity class Foo foo that contains Collection<Bar> bars . I've tried
I have a main NSMutableDictionary that contains a collection of others NSMutableDictionary. The thing

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.