I have some web application written in c#, mvc and mssql.
There is some form on which user can choose some products.
There are two grids in the form. One grid shows products that user can select for future processing. Other grid shows products already selected.
This work like this:
1. User select products from first grid by checkbox
2. Then he click button ‘add’
3. After this, grids are refreshed. Second grid shows added products, and First grid shows all products without products from second grid.
Currently there is about 50.000 products in database.
The problem is with the grid refreshing, when user select too many products to add.
Sql for frist grid looks like:
SELECT ProductId, Name, Description, {other columns}
FROM Products
WHERE ProductId NOT IN ({ list of selected ProductId to add })
If { list of selected ProductId to add } has to many elemets (i.e 10.000) sql statement executes too long, or even gets timeout.
I got stuck with this, and don’t have any idea how to solve that problem.
Any help will be greatly appreciated
Thanks for your ideas and suggestions.
My current solution is to get all porducts from db (filtered if needed) and exclude selected products directly in c# code (not in sql statement).
I did some test, and it’s work in my scenario pretty well.
i.e. I can add 100.000 products to second grid in time below 2 sec.
I also think about caching sql results. It could give even better performance.
If you know any downsides of this solution, please let me now.