sql - Find where row value is inside a list -


companylist companylist = new companylist(); companylist.matchcompanies(); companylistobject[] companylistobject = companylist.companylist;  list<double> companylist = new list<double>(); foreach (var company123 in companylistobject) {     if (company123.parentcompany == companyid)     {         companylist.add(company123.companyid);     } }  ienumerable<racallratesmatched> items =      db.racallratesmatched.where(row => row.accountcode == companyiddouble); 

i want pull results row value present in list. list contains company ids. it's quite short list, 3-5 elements long. rather checking if row equal 1 of list values. can check if equal more of them?

bear in mind can't use || statements in fixed context list size vary. example compare list[0] || list[1] || list[2] fixed , i'll exception if long.

i can't make multiple calls database because each call view takes long time build. can in 1 call?

use .any()

e.g.

mycompanylist.any(x => x.equals(mycompanyname)); 

where mycompanylist list of strings in example. can applied list of ints too. etc.

you can compare parameter in complex classes, or type of valid equality check.

more examples : http://www.dotnetperls.com/any


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -