jqGrid & ASP.NET 4 MVC: How to make search implementation on a DBContext repository and 'calculated' properties?

前端 未结 2 539
借酒劲吻你
借酒劲吻你 2021-01-17 04:57

I\'m trying to implement jqgrid search on MVC, following the interesting answer by @Oleg, regarding the question: ASP.NET MVC 2.0 Implementation of searching in jqgrid.

2条回答
  •  甜味超标
    2021-01-17 05:12

    It seems to me that you have some pure Entity Framework problems. I think that you can solve the problem by moving the calculation of the Ticket.Calculated property directly in the following statement

    var queryDetails = (from item in pagedQuery
                        select new {
                            ...
                            (item.Amount + item.Tax), // Calculated directly
                            ...
                        }).ToList();
    

    In the case the calculation of the property will not use Entity SQL and so you will have no EntitySqlException exception. Such approach should work. You can encapsulate the calculation of the property in any function if needed.

    Another way can be the usage the calculation of the additional property directly in JavaScript code on the client side. For example if you need to display tree dependent columns in the grid: amount, tax and the total amount which is just the sum of amount and tax you can do this on the client side in the JavaScript code. jqGrid has beforeProcessing callback function which will be called before the data returned from the server will be processed. So You can enumerate items in the data.rows and set total property of every item as the sum of amount and tax (converted from String to Number). In the way you will reduce the size of data which will be send between server and the client.

提交回复
热议问题