Click here to Skip to main content
15,896,727 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have database table in which i am storing multiple status of same employee ,and then get these record in to the report,it work fine ,problem is here when i add a little bit change in the his status that status add as fresh record because i want to save previous one so can use update method.now i want to get last record of that employee c# code is here.
C#
var incharge = _service.GetEmployeeStatusBySector_Id(sectorId).Where(x => x.DutyType_Id == 7 && x.EmployeeStatusType_Id == 1 && x.IsDutiable == true);
           foreach (EmployeeStatus Inchargesector in incharge)
           {
               var emp = _service.GetEmployee(Inchargesector.Employee_Id);

               foreach (var empp in incharge)
               {
                   dataset.InchargeSector.Rows.Add(Inchargesector.EmployeeShift_Id, emp.Name, emp.RankName, emp.CellNo);
                   InchargeSector.Remove(empp);
               }

           }

i cant use it as follow that create problem
C#
var incharge = _service.GetEmployeeStatusBySector_Id(sectorId).Where(x => x.DutyType_Id == 7 && x.EmployeeStatusType_Id == 1 && x.IsDutiable == true).last();
Posted
Updated 9-Jan-15 10:26am
v2

1 solution

In any scenario to 'last' (and 'first' and any selection based on position) to have any meaning you have to define an ORDER, what you did not...
Find the proper columns to do the ordering than go and read how to utilize it in LINQ: http://msdn.microsoft.com/en-us/library/vstudio/bb399396%28v=vs.100%29.aspx[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900