c# - Randomly select row of data using linq statement -
hi there have table called word table. following fields: wordid, word, hint, category. table has 40 rows of data. randomly select row of data matches criteria. heres code:
public list<wordtable> get(string diff, string cat) { using(entities obj = new entities()) { var qry = (from c in obj.wordtables c.difficultylevel == diff && c.category == cat select c); return qry.tolist(); } }
for random selection can ,
public wordtable get(string diff, string cat) { var qry = (from c in obj.wordtables c.difficultylevel == diff && c.category == cat select c); var list = qry.tolist(); random r = new random() var element = list [ r.next(0, list.count-1)]; return element; }
Comments
Post a Comment