var resultList = userList.GroupJoin(departList, u => u.departmentId, a => a.id, (u, a) => new { id = u.id, serialNumber = u.serialNumber, nickName = u.nickName, departName = a.FirstOrDefault(x => x.id == u.departmentId) == null ? "Null" : a.FirstOrDefault(x => x.id == u.departmentId).name }).Select(o => o).ToList();
public class UserInfo { public string id { get; set; }//设备id public string serialNumber { get; set; }//设备编号 public string nickName { get; set; }//设备名称 public string portrait { get; set; }//角色 public string departmentId { get; set; }//部门ID public string terminalType { get; set; }//终端类型:1 一期;2 二期;5 三期 }
public class DepartmentInfo { public string id { get; set; }//部门id public string name { get; set; }//部门名称 public string parentId { get; set; }//上级机构ID public string sort { get; set; }//排序(同部门下的显示顺序) }