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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:42:26+00:00 2026-06-13T10:42:26+00:00

Two subsequent FROM clauses get translated into a call to SelectMany . a) var

  • 0

Two subsequent FROM clauses get translated into a call to SelectMany.

a)

var query = from c_1 in collection_1
            from c_2  in collection_2 
            from c_3 in collection_3
            select ...

Correct me if I’m wrong, but I think query expression gets translated into a code semantically equivalent to:

collection_1.SelectMany(c_1 => c_1.collection_2.
               SelectMany(c_2 => c_2.collection_3.
                     Select(c_3 =>  ... )));

Is from c_3 in collection always “bound” to c_2 range variable? With the term “bound” I’m asking whether the entire collection_3 gets enumerated for each c_2 element?

b) Assuming I’m correct under a), is c_3 always “bound” to range variable defined closest to it?

c) If answer to b) is true, then c_3 is bound to c_2 even in the following example:

var query = from c_1 in collection_1
            from c_2  in collection_2 
            where ...
            from c_3 in collection_3

d) Is in next query c_3 bound to a ( ie for each a the entire groupAandB will be enumerated ):

var query_1 =  from a in groupA
               join b in groupB on a equals b
                  into groupAandB
               from c_3 in groupAandB
               select c_3;

e) Here I’m assuming that answer to d) is that c_3 is indeed bound to a. But when looking at the code into which query_1 is translated at compile time, we could instead argue that c_3 is actually bound to anonymous type a_1 ( ie new { a, groupAandB = os } )?!

groupA.GroupJoin(groupB, a => a, b => b, (a, os) => new { a, groupAandB = os } ).
             SelectMany(a_1 => a_1.groupAandB );

f) Keeping in my mind into what query_1 gets translated, couldn’t we argue that any assumptions I made under d) are perhaps conceptually correct, but technically wrong, since at compile time there isn’t any c_3 variable, or perhaps there is c_3 defined somewhere under the hood, but it is actually bound to an anonymous type and not to a?

EDIT:

1)

with Join, the “second” collection can’t depend on which value you’re
currently “looking at” from the first collection,

a) I assume you essentially mean that we can’t join customers to a collection ( ie c.Orders ) returned by current value of c :

var query1 = from c in customers
             join o in c.Orders on c.CustomerId equals o.OrderID // this won't work
             select new { c.Name, o.OrderID, o.OrderDate };

b) Btw, why is such a join not allowed ( I’m assuming it would be technically feasible to make such a join ) or perhaps why it doesn’t make sense?

2)

“The C# specification gives the explicit transformation involved”

Could you elaborate what you mean by “explicit transformation involved” and how it relates to e) and f) questions?

thank you

  • 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-13T10:42:27+00:00Added an answer on June 13, 2026 at 10:42 am

    Query a gets compiled to:

    collection1
       .SelectMany(c1 => collection2, (c1, c2) => new { c1, c2 })
       .SelectMany(t0 => collection3, (t0, c2) => new { t0.c1, t0.c2, c3 })
    ;
    

    collection2 is enumerated for each element in collection1; collection3 is enumerated for every combination of items in the result.

    If collection1 contains { 1, 2 }, collection2 contains { 11, 12 }, and collection3 contains { 21, 22 }, then the result will be:

    |----|----|----|
    | c1 | c2 | c3 |
    |----|----|----|
    |  1 | 11 | 21 |
    |  1 | 11 | 22 |
    |  1 | 12 | 21 |
    |  1 | 12 | 22 |
    |  2 | 11 | 21 |
    |  2 | 11 | 22 |
    |  2 | 12 | 21 |
    |  2 | 12 | 22 |
    |----|----|----|
    

    Query c gets compiled to:

    collection1
       .SelectMany(c1 => collection2, (c1, c2) => new { c1, c2 })
       .Where(t0 => ...)
       .SelectMany(t0 => collection3, (t0, c3) => new { t0.c1, t0.c2, c3 })
    ;
    

    collection3 is enumerated for every combination of items from collection1 and collection2 which pass the filter.

    For query d, each c_3 will be the list of items from groupB which match an element from groupA, so if I’ve understood your terminology correctly, it is indeed “bound to” a.

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

Sidebar

Related Questions

I want to bind columns in a DataGridView to pull values from two different
Suppose I get data from a service (that I can't control) as: public class
Update: Currently looking into NSSET's minusSet links: Comparing Two Arrays Hi guys, Could benefit
Mending a bug in our SAP BW web application, I need to call two
I have two collections of objects of different type. Lets call them type ALPHA
Two trees are said to be identical if they contain same set of elements
Two questions only: I have a website including a section of Blog in wordpress.
Two days ago I spontaneously bought myself a domain. The day before that, I
Two related questions. First: does this repro for you or is it something local
Two tables. I have column a (datetime type) and column b (numeric type) in

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.