Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a table where multiple record against one employee present,and there are a number of employee also. i want to get list of last records enter against all employee.
Posted

Hi,

As you are having multiple records for multiple employees to find the latest record you have to use "Order By" clause with "Descending" property.

Then you have to use "Group By" clause to group your employees.

Then you have to select the "Partition By" record from the descending order based on the employeeID and select the top one record.

Hope you got the logic to implement the solution here.

For reference use this link.

Thanks
Sisir Patro
 
Share this answer
 
v4
C#
var Employees = Emp.OrderByDescending(x => x.CreatedDate).GroupBy(x => x.EmpID).Select(x => x.First()).AsQueryable();



It will return the record of each EmployeeID with max Creation date.
Hope this helps you.

Updated
 
Share this answer
 
v2
C#
var records =
         context.Employees.GroupBy(e=>EmpID)
                          .Select(grp=>grp.OrderByDescending(g=>g.enterDate).First());
 
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