i am using following query to get my data, its working ok but i need modification in it . new query IN EF
var sectorEmployees = from ec in entities.EmployeeCategories.Where(x => x.Category_Id == 1 || x.Category_Id == 2
&& x.Sector_Id == sectorId)
join es in entities.EmployeeStatus.Where(x => x.EmployeeStatusType_Id == 1)
on ec.Employee_Id equals es.Employee_Id
select es;
BUT problem is that there are multiple record against one employee but i want last records of that employee from the table, i was using following query that was fullfilling my needs
var sectorEmployees = _service.GetEmployeeStatusBySector_Id(sectorId).OrderByDescending(x => x.EndDate)
.GroupBy(x => x.Employee_Id).Select(x => x.LastOrDefault()).ToList();
how can i can modify 1st query to full fill my needs that is done by 2nd query.

Sajid HussainPosted Mar 27, 2015, 3:48 AM
that full fill all requirement
Ramesh MaruthiPosted Mar 26, 2015, 9:37 AM
Please see the below query :
var sectorEmployees = (from ec in entities.Employee
join es in entities.EmployeeStatus
on ec.Employee_Id equals es.Employee_Id
where(ec.Category_Id == 1 || ec.Category_Id == 2
&& ec.Sector_Id == sectorId) &&(es.EmployeeStatusType_Id == 1)
Orderby es.EndDate descending
group es by es.Employee_id into g
select g.LastOrDefault());