user3163213
user3163213

Reputation: 701

contains any of string linq

I have this linq query-

Where string Creative and Artistic would be match.

It is a query of records where particular record contains any of these string matches.

Query-

Public ActionResult Creative(){

  string[] stringArray = {"Creative","Artistic"};
  var creativelist = (from u in db.CardTables
                      Where u.TagName.Any(stringArray.Contains)
                      select SomeModel{})
                     .ToList();
}

I want to select where column TagName contains any of these strings or both.

Upvotes: 0

Views: 121

Answers (2)

if this has to be done using lambda then i would do like

var creativelist = db.CardTable.Where(x=>stringArray.Contains(x.TagName)).ToList()

so in your case

string[] stringArray ={"Creative","Artistic"};
var creativelist = (from u in db.CardTables
                    where stringArray.Contains(u.TagName))

Upvotes: 1

OneFineDay
OneFineDay

Reputation: 9024

string[] stringArray ={"Creative","Artistic"};
var creativelist = (from u in db.CardTables
                    where stringArray.Contains(u.TagName))

Upvotes: 2

Related Questions