c# - Find all articles that contain words with linq -
trying learn linq bumping against wall here.
im trying find articles contain multiple strings, not sure how use .contains when passing in list.
private void searcharticles() { adminentities db = new adminentities(); var searchstrs = new list<string> {"search_string1", "search_string2"}; var artlistfull = db.view_m02articles_searchpublished(0, "").tolist(); var artlist = artlistfull.findall(n => n.bodytext.contains(searchstrs)); label1.text = artlist.count.tostring(); repeater1.datasource = artlist; repeater1.databind(); }
what wold correct syntax here?
[edit] supposing bodytext
of type string
you can try this:
//the article body must contain "all" search terms var artlist = artlistfull.where(art => searchstrs.all(art.bodytext.contains));
or
//the article body must contain "at least one" of search terms var artlist = artlistfull.where(art => searchstrs.any(art.bodytext.contains));
[edit 2] replacing str => art.bodytext.contains(str)
art.bodytext.contains