c# - Querying the id of an entity using linq -
in following method trying fetch username passing id value ids passed parameter can multiple values in csv's (eg: 1,2) , returned calling function ienumerable.
code follows below :
[nonaction] public static ienumerable<userprofile> searchcmsadmins(string s) { //var searchresults = entities.userprofiles.where(item =>item.username.contains(s)); //return searchresults; string[] ids = s.split(','); ienumerable<userprofile> results = null; ilist<userprofile> user = new list<userprofile>(); (int = 0; < ids.length; i++) { int id = convert.toint32(ids[i].tostring()); var entity = entities.userprofiles.where(item => item.userid); //user.add(entity); results = results.concat(entity); } return results; }
any appreciated.
try using contains
:
var results = entities.userprofiles.where(item => ids.contains(item.userid));
Comments
Post a Comment