public List<MAS_EMPLOYEE_TRANSFER> GetEmployeeTransferListForHR(TimecardDataContext TimecardDC)
{
List<MAS_EMPLOYEE_TRANSFER> objEmployeeTransferList = null;
try
{
objEmployeeTransferList = new List<MAS_EMPLOYEE_TRANSFER>();
objEmployeeTransferList = TimecardDC.MAS_EMPLOYEE_TRANSFER.Where(
employee =>
employee.HR_ADMIN_IND=="Y").ToList();
}
finally
{
}
return objEmployeeTransferList;
}
It shows all list of values where hr admin indicator=yes. But I have to get hr admin=yes and distinct(empid) from the table MAS_EMPLOYEE_TRANSFER. How to get distinct empId from the the objEmployeeTransferList.
Have try making it
.Distinct().ToList();
You can refer here LINQ: Distinct values
List<int> ids = objEmployeeTransferList
.Select(e => e.empId)
.Distinct()
.ToList();
Also you can make this on server side without creating in-memory employee list with all admin records:
List<int> ids = TimecardDC.MAS_EMPLOYEE_TRANSFER
.Where(e => e.HR_ADMIN_IND == "Y")
.Select(e => e.empId)
.Distinct()
.ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With