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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:07:57+00:00 2026-06-03T21:07:57+00:00

I understand that if you have some function in a linq query that does

  • 0

I understand that if you have some function in a linq query that does not map to a sql query then you must call .AsEnumerable() first:

var model = _service.GetQuery
                    .Where(data => data.SomeFlag == true)
                    .Select(data => new { Foo = CalculateFoo(data.Bar); });

Cannot be executed by linq to sql, but by adding AsEnumerable() we can make the .Select() clause execute by linq to objects instead:

var model = _service.GetQuery
                    .Where(data => data.SomeFlag == true)
                    .AsEnumerable()
                    .Select(data => new { Foo = CalculateFoo(data.Bar); });

But what if the dataset is very large – what affect does AsEnumerable have on paging? If I say:

var page = model.Skip((page > 0 ? page - 1 : 0) * rows).Take(rows);

Because model is now IEnumerable instead of IQueryable, when we say model.Skip().Take(), does it have to first load the entire dataset from the database before it can skip and take? (This would defeat the purpose of paging)

EDIT: The question was written generically – these are the concrete details:

I do not have control over the paging. I am generating a model and passing it to a grid component (DevExpress in this case, but could be any grid). It is the grid component that issues the paging commands. Any solution that involves using .Skip().Take() before AsEnumerable() is not possible here.

So I need to be able to pass this model to the grid, and also at the same time make sure that the model uses deferred execution:

var model = _service.GetQuery
                .Where(data => data.SomeFlag == true)
                .Select(data => new {
                     data.Id,
                     data.Customer.Code,
                     data.Customer.Name,
                     // etc, select a few other properties 
                     Foo = CalculateFoo(data.Bar);
                });

So now I have a rock vs hard place problem:

  • If I pass that model to the grid, it will throw an exception when showing the current page because linq to sql cannot execute CalculateFoo()
  • If I add AsEnumerable() then the grid can show the current page, but it has to load the entire dataset to do so (loading many thousands of rows just to display 200 of them)
  • If I leave the Foo column out of the model then we have deferred execution back again, but the grid is missing a column
  • 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-03T21:07:59+00:00Added an answer on June 3, 2026 at 9:07 pm

    If you make paging, you need …a page, and a total

    so

    var query= _service.GetQuery
                        .Where(data => data.SomeFlag == true);
    
    ViewBag.Total = query.Count();
    var model = query.Skip((page > 0 ? page - 1 : 0) * rows).Take(rows)
                        .AsEnumerable()
                        .Select(data => new { Foo = CalculateFoo(data.Bar); });
    

    Because model is now IEnumerable instead of IQueryable, when we say model.Skip().Take(), does it have to first load the entire dataset from the database before it can skip and take? (This would defeat the purpose of paging)

    That’s a fact : you shall always have only your “accepted by linq2entites” query before “paging”.

    EDIT

    I do not have control over the paging. I am generating a model and passing it to a grid component (DevExpress in this case, but could be any grid). It is the grid component that issues the paging commands. Any solution that involves using .Skip().Take() before AsEnumerable() is not possible here.

    Well, “usually” Grid-systems allow (telerik) (or have only (MvcContrib) custom paging (which means you have to provide the “selected page” results + the total count, as in my answer).

    I made a search (you could go further) on “DevExpress custom paging”, which give few results. Don’t know if they’re interesting for you.

    Examples of answer

    http://www.devexpress.com/Support/Center/p/Q264453.aspx

    http://community.devexpress.com/forums/p/98848/338135.aspx

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

Sidebar

Related Questions

I understand that some countries have laws regarding website accessibility. In general, what are
i have some code that i am trying to recompile and understand, but i
I have some legacy C++ code that I am trying to understand a bit
I have some questions about basic CSS that I was unable to understand or
Hi We have some php code using the file_get_contents() function, and I understand this
I'm using Grails 1.3.7. I have some code that uses the built-in base64Encode function
I understand that whenever I have a function that has more than four arguments
Ok, I understand that using strings that have special characters is an encoding issue.
Just trying to understand that - I have never used it before. How is
I understand that floating point calculations have accuracy issues and there are plenty of

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.