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
Post a Comment