c# - randomize Select do not work -


i wrote code that's going accidentally bring row of data

i want 5 row chosen randomly not work , return value

everything true, part related random return not work anymore

public list<tblinvoice> admin_getrowssendproduct(string startdate, string enddate, int status = -1, bool randomize = false) {     ltsproductdatacontext db = new ltsproductdatacontext(bllbase.bllbase.connectionstring);     iqueryable<tblinvoice> xxx = db.tblinvoices.where(p => p.status == true);     datetime _startdate = datetime.minvalue;     datetime _enddate = datetime.minvalue;     if (xconvertor.tostring(startdate) == "" || xconvertor.tostring(enddate) == "")     {         if (string.isnullorempty(startdate) == false)             _startdate = bllbase.xdatetime.datexorshid2datemiladi(startdate.tostring());         if (string.isnullorempty(enddate) == false)         {             _enddate = bllbase.xdatetime.datexorshid2datemiladi(enddate.tostring());             if (_startdate == _enddate) { _enddate = _startdate.adddays(1); }         }         xxx = xxx.where(p =>         (p.status == true) &&                         (_startdate == datetime.minvalue || p.date >= _startdate) && (_enddate == datetime.minvalue || p.date <= _enddate));     }     else if (xconvertor.tostring(startdate) != "" && xconvertor.tostring(enddate) != "")     {         _startdate = bllbase.xdatetime.datexorshid2datemiladi(startdate.tostring());         _enddate = bllbase.xdatetime.datexorshid2datemiladi(enddate.tostring());          xxx = xxx.where(p => p.date <= _enddate && p.date >= _startdate && p.status == true && p.sendstatus == status);     }      xxx = xxx.where(p => (status == -1 || p.sendstatus == status) && p.status == true).orderbydescending(p => p.date);        if (randomize)     {         random rnd = new random();         xxx = xxx.orderby(x => rnd.next());         //xxx = xxx.orderby(o => guid.newguid());         xxx = xxx.take(3);         return xxx.where(p => (p.ispostalpayment == null || p.ispostalpayment == false)).tolist();     }     else     {         return xxx.where(p => (p.ispostalpayment == null || p.ispostalpayment == false)).tolist();     }     //return xxx.where(p => p.paymenttype != 4).tolist(); } 

do not work section:

xxx = xxx.orderby(x => rnd.next());  

or

xxx = xxx.orderby(o => guid.newguid()); 

if (randomize) {     list<tblinvoice> _result = db.tblinvoices.tolist();      var _temp = xxx.where(p => (p.ispostalpayment == null || p.ispostalpayment == false)).tolist();     _result = _temp.orderby(o => guid.newguid()).take(5).tolist();     return _result; } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -