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

前端 未结 2 510
借酒劲吻你
借酒劲吻你 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.

    0 讨论(0)
  • 2021-01-17 05:25

    The best working solution to my problem has been resolved following the precious hints of Mr @Oleg: I moved the calculated properties into SQL Server, creating Computed Columns for each property. Now it works fine and it is really fast!

    I lost more time trying to get working the calculated properties with ObjectSet, than create new computed columns directly in the db! As rightly pointed by Oleg, simple things are always the best!

    Just another hint, for who's using EF Codefirst: if you want to use computed properties, you must DROP COLUMNS after db creation and putting [DatabaseGenerated(DatabaseGeneratedOption.Computed)] attribute above property, as specified in here too.

    Thank you very much Oleg! I hope this solution may help other people!

    0 讨论(0)
提交回复
热议问题