Page 1 of 1

complex conditional where using lambda expression

Posted: Mon 03 May 2010 11:56
by eran
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.

Posted: Fri 07 May 2010 11:19
by AndreyR
Your code snippet is correct. What problem do you encounter with it?
It should be translated to the following SQL:

Code: Select all

SELECT *
FROM Query t1
WHERE t1.SectionID LIKE '%;111;%'
This seems to be the query you need.