c# - Getting only Last items in the List -
i have foreach loop retrieve list items like:
//gets records of employee, var emps = (from n in db.timesheets n.empid_id == 123 select n); //gets number of records , ex: no. of records 2. int count = emps.count();//ex: count = 2 //timesheet model class contains , set properties below list<timesheetmodel> list = new list<timesheetmodel>(); objts.gettimesheetdetails = list; if (emps.count() > 0) { timesheetmodel model=new timesheetmodel() foreach (timesheet ts in emps) { //from model class //from database "timesheet" table model.proj_id = ts.proj_id; model.sun_hrs = ts.sun_hrs; model.mon_hrs = ts.mon_hrs; model.tue_hrs = ts.tue_hrs; model.wed_hrs = ts.wed_hrs; model.thu_hrs = ts.thu_hrs; model.fri_hrs = ts.fri_hrs; model.sat_hrs = ts.sat_hrs; objts.gettimesheetdetails.add(model); //here adding last record of table. want add records of table last record adding list } return view("timesheet", objts);// returning last record of database table }
the problem when getting values of record database, , adding list, last record adding, not records of table.
what solution this. please me anyone.
in code change
if (emps.count() > 0) { timesheetmodel model=new timesheetmodel() foreach (timesheet ts in emps) { //from model class //from database "timesheet" table model.proj_id = ts.proj_id; model.sun_hrs = ts.sun_hrs; model.mon_hrs = ts.mon_hrs; model.`enter code here`tue_hrs = ts.tue_hrs; model.wed_hrs = ts.wed_hrs; model.thu_hrs = ts.thu_hrs; model.fri_hrs = ts.fri_hrs; model.sat_hrs = ts.sat_hrs; objts.gettimesheetdetails.add(model); //here adding last record of table. want add records of table last record adding list } }
to
if (emps.count() > 0) { foreach (timesheet ts in emps) { timesheetmodel model=new timesheetmodel() //from model class //from database "timesheet" table model.proj_id = ts.proj_id; model.sun_hrs = ts.sun_hrs; model.mon_hrs = ts.mon_hrs; model.`enter code here`tue_hrs = ts.tue_hrs; model.wed_hrs = ts.wed_hrs; model.thu_hrs = ts.thu_hrs; model.fri_hrs = ts.fri_hrs; model.sat_hrs = ts.sat_hrs; objts.gettimesheetdetails.add(model); //here adding last record of table. want add records of table last record adding list } }
Comments
Post a Comment