Linq to DataSet filter one column for multi keywords

903 views Asked by At

I have code like this:

 var modele = from model in ds.Tables["modele"].AsEnumerable()
                         where model.Field<string>("KRAJ_PRODUKCJI") == krajText
                         && model.Field<string>("FABRYKA") == fabrykaText
                        // && model.Field<string>("NAZWA") == itemId 
                         orderby model.Field<string>("NAZWA")
                         select model;

In the commented out line I need to dynamically generate a where clause or check that the field NAZWA is equal to one of multiple keyword in itemId which is a list with a few keyword to check with || between.

Is it possible to do this?

2

There are 2 answers

4
Chris Pfohl On

Have you tried something like:

where itemId.Contains(model.Field<string>("NAZWA"))

I'm not sure if that's what you're looking for, but it might be.

@korchev's won't work because you want an "||".

Mam nadzieje ze to pomocne.

0
Bazzz On

Might not work straight out-of-the-box, but I'm guessing you should look for your answer in this direction:

var keywords = itemId.split("||");

var model = from m in ds.Tables["modele"].AsQueryable();

model = model.Where(m => keywords.Contains(m.Field<string>("NAZWA"));