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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:11:39+00:00 2026-05-18T22:11:39+00:00

I have seen this code Sortable JqGrid using LINQ to MySQL (DbLinq) and Dynamic

  • 0

I have seen this code Sortable JqGrid using LINQ to MySQL (DbLinq) and Dynamic LINQ – Orderby doesn't work
and trying to make it work. But it’s giving error:

Cannot order by type ‘System.Object’

See the line in the code with Error Here.

[HttpPost]
public ActionResult MyGridData(string sidx, string sord, int page, int rows)
{
    IQueryable<Company> repository = companyRepository.GetGridCompanies();

    int pageIndex = Convert.ToInt32(page) - 1;
    int pageSize = rows;
    int totalRecords = repository.Count();
    int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);

    // first sorting the data as IQueryable<Ticket> without converting ToList()
    IQueryable<Company> orderdData = repository;

    PropertyInfo propertyInfo = typeof(Company).GetProperty(sidx);

    if (propertyInfo != null)
    {
        orderdData = String.Compare(sord, "desc", StringComparison.Ordinal) == 0 ?
            (from x in repository
             orderby propertyInfo.GetValue(x, null) descending
             select x) :
            (from x in repository
             orderby propertyInfo.GetValue(x, null)
             select x);
    }

    // paging of the results
    IQueryable<Company> pagedData = orderdData
        .Skip((page > 0 ? page - 1 : 0) * rows)
        .Take(rows);

    var jsonData = new
    {
        total = totalPages,
        page,
        records = totalRecords,
        rows = (
            from o in pagedData  //ERROR HERE : Cannot order by type 'System.Object'
            select new
            {
                i = o.companyID,
                cell = new string[] { o.companyID.ToString(), o.companyName, o.companyCity, o.companyState }
            }).ToArray()
    };
    return Json(jsonData);
}

public class CompanyRepository
{
    SandGridDataContext db = new SandGridDataContext();

    // Send Total Number of Companies
    public int CompanyCount()
    {
        return db.Companies.Count();
    }

    public IQueryable<Company> GetGridCompanies()
    {
        return db.Companies;
    }

    public Company GetCompany(int id)
    {
        return db.Companies.SingleOrDefault(d => d.companyID == id);
    }

}

//JS code

jQuery().ready(function () {
    var lastSel;
    jQuery("#sandgrid").jqGrid({
        url: '/JQSandbox/MyGridData/',
        datatype: 'json',
        mtype: 'POST',
        height: 255,
        width: 640,
        colNames: ['Index', 'Name', 'City', 'State'],
        colModel: [
                { name: 'companyID', index: 'companyID', width: 5 },
                { name: 'companyName', index: 'companyName', width: 30 },
                { name: 'companyCity', index: 'companyCity', width: 30 },
                { name: 'companyState', index: 'companyState', width: 4, sortable: false}],

        pager: jQuery('#sandgridp'),
        rowNum: 5,
        rowList: [5, 10, 20, 50],
        sortname: 'companyID',
        sortorder: "desc",
        viewrecords: true,
        altRows: true,
        caption: 'Sandbox Grid',
        ondblClickRow: function (id) {
            if (id && id !== lastSel) {
                jQuery('#sandgrid').restoreRow(lastSel);
                lastSel = id;
                alert("You've seleted " + id);
            }
        },
        subGrid: true,
        subGridUrl: '/JQSandbox/MySubGridData/',
        subGridModel: [
        {
            name: ['Name', 'Department', 'Hire Date', 'Supervisor'],
            width: [80, 20, 80, 10],
            align: ['left', 'left', 'left', 'center'],
            params: ['companyID']
        }]
    }).navGrid('#sandgridp', { edit: false, add: false, del: false });

//Company class is Linq to Sql entity with fields below.

companyID,
companyName, 
companyCity,
companyState
  • 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-18T22:11:39+00:00Added an answer on May 18, 2026 at 10:11 pm

    I spent too much time to resolve this.
    Please check Order LINQ by "string" name.

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

Sidebar

Related Questions

I've seen second one in another's code and I suppose this length comparison have
I have seen this problem arise in many different circumstances and would like to
I have seen this link: Implementing Mutual Exclusion in JavaScript . On the other
I have seen this macro defined before but never really knew its purpose. Can
I have seen this in a lot of XML comments for classes in the
I have seen this syntax in MSDN: yield break , but I don't know
I have seen this question: Are there any decent UI components for touch screen
I have seen this mentioned a few times and I am not clear on
Now I have seen this question in another forum but it didn't had an
I am pretty sure I have seen this before, but I haven't found out

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.