- Table:Employee
- 部门:Employee.DeptCode
- 上级部门:Employee.SuperiorDept
- 工号:Employee.Emplid
- Distinct的原因是递归出来的资料有重复。
[Fact]
private void TestX()
{
var Query= GetEmpListData("PPM100");
var Result= Query.Select(x => x.Emplid).Distinct().ToList();
}
private List<Employee> GetEmpListData(string DepartmentCode)
{
using (EmpDContext db = new EmpDContext())
{
var Query = db.Employee.Where(a => a.SuperiorDept == DepartmentCode).ToList();
return Query.Concat(Query.SelectMany(t => GetData(t.DeptCode))).ToList();
}
}