I have a List and I want to see if any of these strings are in any of 3 fields of a single sql record using linq to sql.
ListA<strings>;
var found=db.People.Where(p=>p.field1 field 2 or field 3 is in ListA). Select this person
var found = db.People.Where(p=>ListA.Contains(p.field1) || ListA.Contains(p.field2) || ListA.Contains(p.field3));
Use this code:
ListA<strings>;
var found=db.People.Where(p=>
ListA.Contains(p.field1) || ListaA.Contains(p.field2)
|| ListaA.Contains(p.field3));
Please, be aware that this will take all the records from the DB and test the condition on the application side.
EDIT: this is just the same code of the other answer, but includes a note on how it works, so I don't delete it. (Changed because of @Adrian lftode comment)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.