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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:25:37+00:00 2026-06-04T00:25:37+00:00

When I have an IQueryable<T> (generic) I can use the Take method to return

  • 0

When I have an IQueryable<T> (generic) I can use the Take method to return only N records from the result set returned by the query.

When I’m using a simple non-generic IQueryable, Take method is not available. Is there an other way to achieve the same result as the Take method?

UPDATE: as Richard pointed, another question solves this problem. In my case, the necessary code was even simpler then the code proposed by Jon Skeet in the other question. That’s my final code:

dynamic tempQuery = originalQuery;
finalQuery = Queryable.Take(tempQuery, numRecords);
  • 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-04T00:25:38+00:00Added an answer on June 4, 2026 at 12:25 am

    Use this extension method:

    public static IQueryable Take(this IQueryable source, int count)
    {
        MethodCallExpression mce = Expression.Call(
            typeof(Queryable),
            "Take",
            new Type[] { source.ElementType },
            source.Expression,
            Expression.Constant(count)
        );
        return source.Provider.CreateQuery(mce);
    }
    

    You can achieve a similar effect with the various extension methods defined on Queryable like Skip and others, provided you match the method signatures and provide well-formed expression trees.

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

Sidebar

Related Questions

I have a DataService returning an IQueryable I breakpoint at the return statement, list
I have a Linq query that returns an object of the type IQueryable<ClassX> .
If I have a query like this: String Category = HttpContext.Current.Request.QueryString[Product].ToString(); IQueryable<ItemFile> pressReleases =
So I have this linq query clause. var ctx = new Context(); IQueryable<Users> consulta
I have a method for sorting generic lists by the object fields: public static
I can't figure out what I am doing wrong. I have the following method:
How would you suggest using AsEnumerable on a non-generic IQueryable ? I cannot use
How can I find a generic overloaded method? For example, Queryable 's public static
I have the following LINQ query that returns two objects from my database. These
Can I create an automatic generic helper method? Let me explain. This is how

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.