Translating this query in LINQ ? (list of like)
- by Erick
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 ...