Translating this query in LINQ ? (list of like)
Posted
by
Erick
on Stack Overflow
See other posts from Stack Overflow
or by Erick
Published on 2011-02-04T14:46:37Z
Indexed on
2011/02/04
15:26 UTC
Read the original article
Hit count: 210
I would like to translate this query in LINQ ... it is very easy to construct if we do it in pure SQL but in dynamically created LINQ query (building a search query based on user input) it's a whole new story.
SELECT * FROM MyTable
WHERE 1=1
AND Column2 IN (1,2,3)
AND ( Column1 LIKE '%a%' OR Column1 LIKE '%b%' )
Now to try to construct this we tried it this way :
if(myOjb.Column2Collection != null)
query = query.where(f => f.Column2.Contains(myOjb.Column2Collection));
if(myObj.Column1Collection != null)
{
// tough part here ?
//query = query.Where(); ...
}
So what would be the best aproach to this normally ?
Note that I am aware of the SqlMethod.Like, tho I can't figure a way to implement it here ...
© Stack Overflow or respective owner