Hello guys,
I'm trying to write a query with a conditional where and i can't find a way to write it in the correct way.
The goal is:
A column named sectionID in the database is a String of values start with “;” and separated by ";".
A function called with a value of an int sectionID .
The where clause of the query should perform something like this:
If (sectionID > 0)
{
Query.Where(item=>item.SectionID.Contains(“;”+sectionID.ToString()+”;”));
}
is there any way to do it like this?
Thanks,
Eran.
complex conditional where using lambda expression
Your code snippet is correct. What problem do you encounter with it?
It should be translated to the following SQL:
This seems to be the query you need.
It should be translated to the following SQL:
Code: Select all
SELECT *
FROM Query t1
WHERE t1.SectionID LIKE '%;111;%'