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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:54:48+00:00 2026-06-15T17:54:48+00:00

I have that class public class jQGridModel { public List<jQGridModelItem> Items { get; set;

  • 0

I have that class

public class jQGridModel
{
    public List<jQGridModelItem> Items { get; set; }

    public class jQGridModelItem
    {
        public DBUser UserItem { get; set; }
        public int ItemsSold { get; set; }
    }
}

and the DBUser class (generated by Entity Framework)

public class DBUser 
{
    public string UserName { get; set; }
    public string UserID { get; set; }
    public string PromoCode { get; set; }
    ...
}

I have jQGridModel object with some Items. And here’s the ‘simple’ problem – I want to sort the Items list asc/desc basing on the UserName

I’ve tried

jQGridModel result = new jQGridModel();
result.Items = GetItems();

result.Items = result.Items.OrderByDescending(x => x.UserItem.UserName).ToList();

but I see that the collenction order does’t change. What am I doing wrong ?

The complete code:

        var query = (from x in db.User
                     where (...)
                     select x);

        var totalRecords = query.Count();

        jQGridModel result = new jQGridModel();

        result.Items = query.OrderBy(x => x.UserID).Skip(page * pageSize)
                            .Take(pageSize)
                            .Select(x => new jQGridModel.jQGridModelItem
                            {
                                UserItem = x,
                                ItemsSold = (from o in db.Order
                                             where
                                                 o.PromoCode.Equals(x.PromoCode)
                                             select o).Count()
                            })
                            .ToList();


  result.Items = result.Items.OrderByDescending(x => x.UserItem.UserName).ToList();
  • 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-15T17:54:49+00:00Added an answer on June 15, 2026 at 5:54 pm

    I should have said it “doesn’t return an IQueryable”, which it doesn’t. So, you get your list in the order you get it, then you are trying to order by a (most likely) lazy loaded property. So you aren’t really doing what you think you are doing. 🙂

    Either place the UserName as a property of the jQGridModelItem, or if you really need the full DBUser entity, you can load it up first, then sort.

    EDIT

    Actually, just specify the proper ordering in the initial orderby:

    result.Items = query.OrderBy(x => x.UserName).Skip(page * pageSize)
                                .Take(pageSize)
                                .Select(x => new jQGridModel.jQGridModelItem
                                {
                                    UserItem = x,
                                    ItemsSold = (from o in db.Order
                                                 where
                                                     o.PromoCode.Equals(x.PromoCode)
                                                 select o).Count()
                                })
                                .ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have that Class : public Class Color { public virtual int Id {
I have class that looks like this: class A { public: class variables_map vm
I have a class that looks like the following: public class MyClass { private
I have a class that looks like this: public class BasePadWI { public WorkItem
I have a class that roughly looks like this: public class ViewModel { public
I have a class that implements InvocationHandler as below: public class MyProxyClass implements InvocationHandler
I have a class that defines its own enum like this: public class Test
I have a class that implements IComparable. public class MyClass : IComparable<MyClass> { public
I have a class that contains a boolean field like this one: public class
Currently I have a class that looks like this: public class MyClass : IMyClass

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.