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;
}
它显示hr admin indicator = yes的所有值列表。但我必须从表hr admin=yes
中获取MAS_EMPLOYEE_TRANSFER
和distinct(empid)。如何从empId
获得明确的objEmployeeTransferList
。
答案 0 :(得分:6)
答案 1 :(得分:4)
List<int> ids = objEmployeeTransferList
.Select(e => e.empId)
.Distinct()
.ToList();
此外,您可以在服务器端进行此操作,而无需创建包含所有管理员记录的内存员工列表:
List<int> ids = TimecardDC.MAS_EMPLOYEE_TRANSFER
.Where(e => e.HR_ADMIN_IND == "Y")
.Select(e => e.empId)
.Distinct()
.ToList();
答案 2 :(得分:0)
你有没有尝试过:
objEmployeeTransferList = TimecardDC.MAS_EMPLOYEE_TRANSFER.Where(
employee => employee.HR_ADMIN_IND=="Y").Distinct().ToList();
答案 3 :(得分:0)
linq中有一个独特的方法可以解决这个问题。
答案 4 :(得分:0)
使用GroupBy脱颖而出
objEmployeeTransferList.GroupBy(x => x.empId).Select(g => g.First()).ToList();