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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:18:41+00:00 2026-05-29T06:18:41+00:00

How can I write this LINQ query by using the extension method syntax? var

  • 0

How can I write this LINQ query by using the extension method syntax?

var query = from a in sequenceA
            from b in sequenceB
            select ...; 
  • 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-29T06:18:41+00:00Added an answer on May 29, 2026 at 6:18 am

    For your future reference, all questions of this form are answered by section 7.16 of the C# specification.

    Your specific question is answered by this paragraph:


    A query expression with a second from clause followed by a select clause

    from x1 in e1
    from x2 in e2
    select v
    

    is translated into

    ( e1 ) . SelectMany( x1 => e2 , ( x1 , x2 ) => v )
    

    So your query:

    var query = from a in sequenceA            
                from b in sequenceB
                select ...;  
    

    Is the same as

    var query =  ( sequenceA ) . SelectMany( a => sequenceB , ( a , b ) => ... )
    

    (Note that of course this assumes that the “…” is an expression, and not, say, an expression followed by a query continuation.)

    hdv’s answer points out that

    var query =  ( sequenceA ) . SelectMany( 
        a => ( sequenceB ) . Select( b => ... ) );
    

    would also be a logically valid translation, though it is not the translation we actually perform. In the early days of LINQ implementation, this was the translation we chose. However, as you pile on more from clauses, it makes the lambdas nest more and more deeply, which then presents the compiler with an enormous problem in type inference. This choice of translation wrecks compiler performance, so we introduced the transparent identifier mechanism to give us a much cheaper way to represent the seamntics of deeply nested scopes.

    If these subjects interest you:

    For more thoughts on why deeply nested lambdas present a hard problem for the compiler to solve, see:

    http://blogs.msdn.com/b/ericlippert/archive/2007/03/26/lambda-expressions-vs-anonymous-methods-part-four.aspx

    http://blogs.msdn.com/b/ericlippert/archive/2007/03/28/lambda-expressions-vs-anonymous-methods-part-five.aspx

    For more information about transparent identifiers, see this post from Wes Dyer, who implemented them in C# 3.0:

    http://blogs.msdn.com/b/wesdyer/archive/2006/12/22/transparent-identifiers.aspx

    And my series of articles about them:

    http://ericlippert.com/2014/07/31/transparent-identifiers-part-one/

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

Sidebar

Related Questions

How can you write this query using a lambda expression or LINQ: SELECT *
How can I write a query similar to this one in LINQ to SQL
In LINQ, you can write a manual SQL query, take the results from it
I have just started Entity Framework & linq and write this query var query
If I'm using a Hashtable , I can write code like this: object item
I have heard that Linq query write once can be run on SQL and
Following on from one of the answers in this thread; Using XQuery in Linq
How to write an update query in EntityFramework using LINQ to Entities? EDIT: And
I am using LINQ to write a query - one query shows all active
How can I write this in such a way that $counter value is 1

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.