Last post Nov 06, 2019 06:17 AM by Brando ZWZ
Nov 05, 2019 05:34 PM|inkaln|LINK
Just a general question on what the best query approach would be to do a fast search based on multiple AND search criteria on the same table. So I will be joining two tables on ID and the records obtained on the 2nd table has a label attached to each of
the User IDs. There will be a search page where user can enter up to 10 search criteria selecting the following for each of the 10 items:
Label name, start and end date
So I want to return all records where the labels are exactly what they enter and fall between start and end date....if user selects another one with an AND, user needs to have the 2nd label with start and end dates that fall between the selected start and
end dates....and another AND the similar way. There could be an OR option or AND option. What's the fastest way to write a sql query, or LINQ to handle this?
Table will have:
UserId, Label, StartDate, EndDate
Nov 06, 2019 06:17 AM|Brando ZWZ|LINK
According to your description, I couldn't understand your requirement clearly. Do you mean you want to know which way will query the data fasterly?
If this is your question, Sql query is faster than linq.If you execute a sql query directly its a one way process whereas if you using linq, first its been converted to sql query and then its executed.
But I think linq is easy to query multiple data sources and it is concise of your code. Linq can generate the baseline query which returns an IQueryable data structure and too much search criterias.
Details you could refer to article: