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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:21:35+00:00 2026-05-25T12:21:35+00:00

I have something similar to this model: public class Product { public int ID

  • 0

I have something similar to this model:

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

  public ICollection<ProductVariation> Variations { get; set; }
}


public class ProductVariation
{
  public int VariationID { get; set; }
  public string Size { get; set; }
  public bool InStock { get; set; }
}

I have a List of Product – called “availableProducts”

List<Product> availableProducts;

I then also have a List of int – requestedVariationNumbers:

List<int> requestedVariationNumbers;

What I’m trying to do is get Products from availableProducts where the Product.Variations collection contains a VariationID that is in requestedVariationNumbers.

So far, I’ve got this:
(Generated by ReSharper based on a series of ugly foreach statements…)

It just seems “dirty” to me…

    var result = (
      from rvn in requestedVariationNumbers
      from product in availableProducts
      from itemVariation in product.ItemVariations
      where itemVariation.ItemNo == rvn
      select product)
      .ToList();
  • 1 1 Answer
  • 1 View
  • 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-25T12:21:35+00:00Added an answer on May 25, 2026 at 12:21 pm

    Try this:

    var result = availableProducts.Where(p => p.Variations
                                               .Any(v => requestedVariationNumbers
                                                         .Contains(v.VariationID)));
    

    This is not really efficient. It would be better if requestedVariationNumbers would be a HashSet, because requestedVariationNumbers.Contains(v.VariationID) is called for every variation in every product in the worst case and for every first variation of every product in the best case.

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

Sidebar

Related Questions

I have this model : public class Person { public string Name { get;
I have a view model public class DeviceModelEntryViewModel { public int ID { get;
I have the following model: public class PersonListModel { .... [Required(ErrorMessage=AppConstants.MustSelectRecordToAttachMessage)] public String SelectedPersonId
I have something very similar to this example: https://developers.google.com/maps/documentation/javascript/examples/directions-simple All I am trying to
This is my custom model binder code for the BaseContentObject class: public class BaseContentObjectCommonPropertiesBinder
I have a model like the following: public class Employee { public Employee() {
Right now I have something like this in my CodeIgniter model: <?php $array =
I have a code similar to this: My View @model MyCode.Models.RemarksModel foreach (var row
I have something similar to that: <table> <tr> <td>Hello,<br/>World!</td> </tr> </table> Both lines Hello,
i have something similar to the following... used a python script to JSON 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.