简体   繁体   中英

Which would be a best way to organize the logic for Filters

I want to refactor a logic to filter the grid of my application. I'd like to implement this logic only in the Database .

So, I have a grid which displays the data from more tables from DB. There are some textBoxes and comboBoxes where it sets the data for each filter it wants.

Now, it is a HUGE Stored Procedure in Database which works this way:

Initially selects [ALL DATA] from tables into a temporary table , after that, according to fields that were filled with data (from application filter), it removes from [ALL DATA] that info which is NOT LIKE SELECTED FILTER

And so on foreach parameter which is set in the filter.

This way consumes much time, because initially selects all data, and then slowly removes those which don't need.

I don't want to create SQL queries on client side. I'd like to do that only to Database, or .... iimmmm, i don't know...

Which would be a best way, very optimized, which would run fast and return results in short time as possible?

I use C# and .NET 4.0 for client side, and MSSQL DB.

Thank you for advices.

That's what ORMs are for. Don't build a dynamic SQL statement on the client side. Rather, build a LINQ query filter by filter. You'll get the benefits of being entirely dynamic, without the risk of SQL injection.

You can look at this for an example.

修改存储过程,使其仅首先在temprorary表中选择所需的数据,而不是选择所有内容,然后删除不需要的内容。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM