sql - dynamically varied number of conditions in the 'where' statement using LINQ -
I am using my first project LINQ (in mvc), so maybe there's something very simple that I remember. However, a day of searching and experimenting does not work, so it works.
I am trying to write a LINQ query (Linux to SQL) in which in many cases where the statement is different from an OR or an AND. We do not know how many conditions are going in the query till runtime. This search is for filter control, where the user can choose multiple criteria for filtering.
Select from table where table.col = 1 or table.col = 2 or table.col = 7 .... 'Other number of conditions
< P> Before I just create the SQL query as a string, while looping over all the situations. However, it seems that there should be a good way to do this in LINQ. I tried to use Expression trees, but they had a second thought for this moment on my head, where the lambda function was to be executed inside the statement such as: < Code> values for matchingRows = matchingRows for each value Where (function (row) row.col = value)
However, it only works for conditions and how do I do the ORS?
I will use it for this dynamic WHERE section makes it very easy.
Comments
Post a Comment