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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:16:48+00:00 2026-05-31T14:16:48+00:00

How do I achive the same result as: var q = db.TableA.AsQueryable(); var q1

  • 0

How do I achive the same result as:

var q = db.TableA.AsQueryable();
var q1 = Queryable.SelectMany(q, a => a.TableB, (a, t) => new { a = a, t = t });
var q2 = Queryable.SelectMany(q1, a=> a.a.TableC, (a, t) = new { a = a, t = t });

by creating an expression tree via Expression.Call:

MethodCallExpression returnCallExpression = Expression.Call(
     typeof(Queryable),
     "SelectMany",
     new Type[] ??????,
     query.Expression,
     a => a.TableB,
     (a, t) => new { a = a, t = t });

I’m researching the other overloads of Expression.Call to see if this can be achieved without declaring type.

My issue is that the number of SelectManys is determined at run-time so I can’t just chain them. And each SelectMany changes the anonymous type of the IQueryable, so I’m having trouble getting around not knowing the type at compile-time.

Any ideas about how to apply n number of SelectMany to an IQueryable are greatly appreciated.

  • 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-31T14:16:49+00:00Added an answer on May 31, 2026 at 2:16 pm

    Do you actually have the lambda expressions “available” such as a => a.TableB or are they dynamic as well?

    You could use something like this perhaps (based on this SO post):

    public Type[] GetSelectManysAnonymousTypes<TSource, TCollection, TResult>(
            IQueryable<TSource> queryable,
            Expression<Func<TSource, IEnumerable<TCollection>>> collectionSelector,
            Expression<Func<TSource, TCollection, TResult>> resultSelector)
    {
        return new [] {
            typeof(Expression<Func<TSource, IEnumerable<TCollection>>>),
            typeof(Expression<Func<TSource, TCollection, TResult>>) };
    }
    

    Or something a bit more complicated could give you back the Type[] together with the Expression[] i.e. array of expressions – ready to call Expression.Call().

    I think the problem you are facing though is, forgetting anonymous types, you don’t know what the collectionSelector parameter lambda looks like if you really have a dynamic, unknown number of SelectMany()’s chained together. Or I may be missing something…

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

Sidebar

Related Questions

I would like to achive the same functinoanlity in the UITextField control as Google
Suppose I have an anonymous class instance var foo = new { A =
I am trying to get the same result I obtain at http://jssha.sourceforge.net/ where I
I have the following linq query var result = from myTypes in context.MyTypes where
Hola check this code. var watch = new Stopwatch(); watch.Start(); var request = HttpWebRequest.Create(new
I am trying to achieve the same behavior as indicated in the following post.
Basically, I want to achieve the same thing as ON DUPLICATE KEY in MySQL.
On the iPhone, how could I achieve the same tiled background effect? For example,
how can i paste something on multiple lines? i'm trying to achieve the same
The use case I want to achive is. 1. Fetch XML from a remote

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.