Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the implementation of dynamic linq query

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "what is the implementation of dynamic linq query". In daily operation, I believe that many people have doubts about the implementation of dynamic linq query. I have consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "what is the implementation of dynamic linq query?" Next, please follow the editor to study!

Demand

Cooperate with EasyUI datagird filter to realize the filtering of multi-fields (arbitrary fields)

Filter specific status or conditions according to business requirements, such as: view closed orders, orders in the last 30 days, and view orders belonging to me. Wait, this logic is fixed and can be reused, but do not want to write the same conditions every time, then I will give my solution below.

Requirement 1 is only a lazy implementation, because datagrid comes with this function, but does not want to draw query conditions according to specific requirements. If the requirement has to do a piece of query condition input on datagrid, then it can only be manually added at the front end and transferred to the backend after the organization. It will not be discussed here for the time being.

Requirement 2 may not be easy to explain. After looking at the code, you will naturally understand why you want to do this and what are the benefits of doing so.

The concrete way of realization

By default, datagrid can filter these columns with several columns. For date fields, between will be used to filter between two times. The number type will provide symbols such as greater than less than. You can try on your own. The principle is that datagrid will generate a Json string based on the value entered in the datagrid header to send background request data.

JSON: format

FilterRules: [{field:field,op:op,value:value}, {field:field,op:op,value:value},]

The usual practice is to make a judgment and add conditions.

View Code

The new method is to dynamically generate a linq expression according to field,op,value. There is no need to make tedious judgments. This code can also be used by other projects and is very useful.

View Code

Code used in conjunction with

For the encapsulation and reuse of fixed query logic, of course, in addition to reuse, it can obviously improve the readability of the code.

Check the sales status of the order, conditional amount, country, date

Call the query method

Customer inquiry according to country and city inquiry

Customer's sales, amount and quantity

Reuse the query method defined above

At this point, the study on "what is the implementation of dynamic linq query" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report