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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:05:59+00:00 2026-05-17T22:05:59+00:00

I have a class structure like so: Person Dogs (dog 1, dog 2, etc)

  • 0

I have a class structure like so:

Person
Dogs (dog 1, dog 2, etc)
Puppies (puppy A, puppy B, etc)

There is one person. He has 1..n dogs. Each dog has 1..n puppies.

I want a list of all the possible combination of puppies, taking 1 puppy from each dog. Eg:

dog 1 puppy A, dog 2 puppy A
dog 1 puppy A, dog 2 puppy B
dog 1 puppy B, dog 2 puppy A
dog 1 puppy B, dog 2 puppy B

If it was in sql tables, i’d do something like the following to ‘multiply’ the tables:

select * from puppies a, puppies b where a.parent='dog1' and b.parent='dog2'

Is there some linq-ish way to do this kinda thing???

Thanks so much

  • 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-17T22:05:59+00:00Added an answer on May 17, 2026 at 10:05 pm

    If I understand the question, you want the Cartesian Product of n sets of puppies.

    It is easy to get the Cartesian Product if you know at compile time how many sets there are:

    from p1 in dog1.Puppies
    from p2 in dog2.Puppies
    from p3 in dog3.Puppies
    select new {p1, p2, p3};
    

    Suppose dog1 has puppies p11, p12, dog2 has puppy p21, and dog3 has puppies p31, p32. This gives you

    {p11, p21, p31},
    {p11, p21, p32},
    {p12, p21, p31},
    {p12, p21, p32}
    

    Where each row is an anonymous type. If you do not know at compile time how many sets there are, you can do that with slightly more work. See my article on the subject:

    http://ericlippert.com/2010/06/28/computing-a-cartesian-product-with-linq/

    and this StackOverflow question:

    Generating all Possible Combinations

    Once you have the method CartesianProduct<T> then you can say

    CartesianProduct(from dog in person.Dogs select dog.Puppies)
    

    to get

    {p11, p21, p31},
    {p11, p21, p32},
    {p12, p21, p31},
    {p12, p21, p32}
    

    Where each row is a sequence of puppies.

    Make sense?

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

Sidebar

Related Questions

I have a Struts + Velocity structure like for example, a Person class, whose
I have a class structure like so: public class Person { public virtual int
I have a class structure that looks like this: class Person { public virtual
I have a class structure like class A: def method1(self): return 1 class B:
I have a class structure like abstract class Animal { public Animal(){ //init stuff..
I have a class structure like: abstract class A { String a; } class
Say I have a structure like: class SomeObject Public Name as String Public Created
I have a files structure like this: Class (folder): - User.php - Rule.php Scripts
I have got the following class structure, and have plenty of classes like C
We have many nodes implemented like this: public class Person{ private String name; private

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.