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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:21:00+00:00 2026-05-13T06:21:00+00:00

I have a classic Order -> Order Row scenario something like this: public class

  • 0

I have a classic Order -> Order Row scenario something like this:

public class Order 
{
    public int Id { get; set; }
    public string Name { get; set; }
    public List<OrderRow> OrderRows { get; set; }
}

public class OrderRow
{
    public int Id { get; set; }
    public int ProductId { get; set; }
    public int Amount { get; set; }
}

and a List<Order>. From that list of orders I want to get a list of all the unique ProductIds.

I solved it like this:

var orders = new List<Order>();
// TODO get the orders from DB
var products = new Dictionary<int,int>();
orders.ForEach(order => order.OrderRows.ForEach(row => products[row.ProductId]=row.ProductId));

but I got questions about my use of Dictionary and why I didn’t use LINQs GroupBy and also comments that it wasn’t very clear how it worked. I think the solution is fine but the comments made me want to try to solve it in LINQ but for some reason I hit a brick wall trying.

How do I get a list of unique products ids from a list of orders with LINQ here?

  • 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-13T06:21:00+00:00Added an answer on May 13, 2026 at 6:21 am

    Untested, but how about:

    var products = orders.SelectMany(o => o.OrderRows)
                         .Select(r => r.ProductId)
                         .Distinct();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The scenario I'm working with looks like this: public interface INativeWindow { ... }
I have a SQL Server database designed like this : TableParameter Id (int, PRIMARY
I have made a site with classic php and mysql functions. I order to
I have a classic HTML select box: Show: <select name=show id=showThreads> <option value=all selected=selected>All</option>
Basically i have a classic vhost with: ServerName www.site.com ServerAlias site.com I would like
I need ideas... I have a classic scenario with a twist, containing the following
This is a classic CS problem I encountered in my work: I have a
I have the classic 'get all rows in one table with number of corresponding
I have reduced a complex schema to the following samples Students StudentID int, Name
We have a large ASP (classic ASP) application and we would like to convert

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.