complex conditional where using lambda expression

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
eran
Posts: 1
Joined: Mon 03 May 2010 11:12

complex conditional where using lambda expression

Post by eran » Mon 03 May 2010 11:56

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.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Fri 07 May 2010 11:19

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.

Post Reply