Assistance with sorting on 'computed' column

2 posts, 0 answers
  1. Ian
    Ian avatar
    4 posts
    Member since:
    Mar 2013

    Posted 16 Apr 2013 Link to this post

    I am using the grid control and having a problem where it is not sorting on a column that is being calculated.  Here's the relevant part of my controller, where I'm performing my LINQ query:

                                 select new Models.ApplicationModels.CustomerModel
                                 {
                                     CustomerID = instance.CustomerID,
                                     CustomerOrders = GetCustomerOrders(instance.CustomerID)
                                 };

    This all displays perfectly fine.  I can sort on CustomerID, but I can't sort on CustomerOrders.  I'm not doing anything special with the binding, just calling it the same way as CustomerID.  

    How can I get this to sort properly?  Would it help if I moved the logic of GetCustomerOrders into a SQL function and made it a computed column there?  I should note that I'd like to be able to sort this across all Customer entities -- and I am looking at a lot of data (millions of rows).  If there is a better way of handling this I'm open to suggestions.

  2. Petur Subev
    Admin
    Petur Subev avatar
    1882 posts

    Posted 18 Apr 2013 Link to this post

    Hello Ian,

    What exactly is happening when trying to sort on that field? I assume that an exception is thrown because the generated expression tree (after applying sorting/ filtering or grouping) contains that calculated field which could not be executed on the database level. 
    Try to move the logic on a database level and share your findings.

    Kind Regards,
    Petur Subev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top