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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:08:04+00:00 2026-05-18T10:08:04+00:00

i have an extension method which a person was really helpful to give me…

  • 0

i have an extension method which a person was really helpful to give me… it does an orderby on IQueryable … but i wanted one to do a normal IQueryable (non generic)

Here is the code, The count and Skip and i think Take are missing .

   public static IQueryable GetPage(this IQueryable query,
         int page, int pageSize, out int count)
    {
        int skip = (int)((page - 1) * pageSize);

        count = query.Count(); //COUNT DOESN'T EXIST
        return query.Skip(skip).Take((int)pageSize); // NEITHER SKIP
    }

Here is the and it works perfectly no errors.

    public static IQueryable<T> GetPage<T>(this IQueryable<T> query,
       int page, int pageSize, out int count)
    {
        int skip = (int)((page - 1) * pageSize);

        count = query.Count();
        return query.Skip(skip).Take((int)pageSize);
    }

Any ideas how i can get around this? I don’t want to change my return types as it works perfectly and i have another extension method called ToDataTable and it also functions on a non generic IQueryable ..

Is there a work around?

Thanks in advance

EDIT

I call it like so on an existing IQueryable

 IQueryable<Client> gen = null;
 IQueryable nongen = null;

 var test = gen.GetPage();  //COMPILES!

 var test 1 = non.GetPage(); // Doesn't compile because GETPAGE
                             // for non generic is broken as it has 
                             // invalid methods like COUNT and SKIP etc.

I tried removing the GetPage non generic version but then my non Generic Iqueryable doesn’t pickup the extension due to the fact its not a Iqueryable but only an IQueryable

  • 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-18T10:08:04+00:00Added an answer on May 18, 2026 at 10:08 am

    Well, quite simply those methods aren’t available for IQueryable. If you look at the Queryable methods you’ll see they’re almost all based on IQueryable<T>.

    If your data source will really be an IQueryable<T> at execution time, and you just don’t know what T is, then you could find that out with reflection… or in C# 4, just use dynamic typing:

    public static IQueryable GetPage(this IQueryable query,
         int page, int pageSize, out int count)
    {
        int skip = (int)((page - 1) * pageSize);
        dynamic dynamicQuery = query;
        count = Queryable.Count(dynamicQuery);
        return Queryable.Take(Queryable.Skip(dynamicQuery, skip), pageSize);
    }
    

    The dynamic bit of the C# compiler will take care of working out T for you at execution time.

    In general though, I’d encourage you to just try to use the generic form everywhere instead – it’s likely to be significantly simpler.

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

Sidebar

Related Questions

I have the following extension method (which is invalid and does not compile ATM):
I have a really simple extension method which is constrained for IComparable instances: public
I have an Extension method which is supposed to filter a Queryable object (IQueryable)
I have an extension method which I can use from the .cs codebehind of
I have a SafeInvoke Control extension method similar to the one Greg D discusses
I have an extension method which uses some configuration settings. I've declared these as
I have the following extension method which asserts that a property (Id) contains a
I have created an HtmlHelper Extension method which returns an encoded string, I have
i have an extension method for IEnumerable which then iterates through the collection, doing
I have an extension method which takes in two list and compares them for

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.