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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:26:44+00:00 2026-05-26T06:26:44+00:00

I need to transform some paginated data from Linq to Entity Framework. The data

  • 0

I need to transform some paginated data from Linq to Entity Framework.
The data should be displayed in MVC Contrib Grid / Pager, so it needs to be paginated and the backend SQL Server should paginate the data.

So I have this code as a working base:

MyEntities db = new MyEntities();
IQueryable<HighScore> highscores = db.HighScores.OrderBy(s => s.Id);
return View(highscores.AsPagination(page.GetValueOrDefault(1), 10));

This generates a pretty paged SQL query with SELECT TOP (10) ... WHERE rownum ETC..
Great, backend SQL Server pagination, the way it should be.

So now I need to transform my entities to a little bit different model.

private HighScoreModel GetUrlForImage(string userId, int? score, bool isAnonymous)
{
  return new HighScoreModel
  {
    // transformation, left out for simplicity
  };
}

I can’t simply do:

var fixedData = from v in highscores
                select GetUrlForImage(v.UserId, v.Score, v.IsAnonymous);

because that will get me (expected):
LINQ to Entities does not recognize the method 'MvcContribTest.Models.HighScoreModel GetUrlForImage(System.String, System.Nullable1[System.Int32], Boolean)’ method, and this method cannot be translated into a store expression.`

So I need ToList() the entities in order to call my translation method, something like this:

var fixedData = from v in highscores.ToList()
                select GetUrlForImage(v.UserId,v.Score,v.IsAnonymous);

Which technically now works, but I have lost the backend SQL Server pagination because the ToList() conversion from IQueryable().

How can I do a server side pagination in this scenario?

  • 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-26T06:26:44+00:00Added an answer on May 26, 2026 at 6:26 am

    What about applying pagination before the ToList then do the transformation:

    var fixedData = from v in highscores.AsPagination(page.GetValueOrDefault(1), 10).ToList()
                    select GetUrlForImage(v.UserId,v.Score,v.IsAnonymous);
    

    EDIT: To use with the MVC Contrib grid you will need to wrap it up with the CustomPagination<T> class this is built in in MVC Contrib:

    public ActionResult Index(int? page)
    {
      var itemsPerPage = 5;
      var db = new MyEntities();
      var totalItems = db.HighScores.Count();
    
      IQueryable<HighScore> highscores = db.HighScores.OrderBy(highscore => highscore.ID);
      var pagedData = from highscore in highscores.AsPagination(page.GetValueOrDefault(1), itemsPerPage).ToList()
                      select highscore;
    
      var transformedData = new CustomPagination<HighScoreModel>(pagedData.Select(highscore => TransformData(highscore)), 
                                                                 page.HasValue ? page.Value : 1, 
                                                                 itemsPerPage,
                                                                 totalItems);
      return View(transformedData);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to transform some article about information technologies from format XHTML or HTML
I am having some problems with an XML transform and need some help. The
I need to serialize/de-serialize some objects into/from string and transfer them as just opaque
I think I need some sort of Schwartzian Transform to get this working, but
I need to transform some xml into html and pdf formats as part of
I am trying to create some javascript links. I need to transform the ID
I need some to help oon generating the XSL file for my XML Data.
I need to transform a string into a number using some oracle built-in methods
I'm working with PostgreSQL. I need to transform http://www.xyz.com/some_uri/index1.html in something like scdfdsffd(some unique
I need to transform/convert/process TransXchange data dump to reduce the size of data as

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.