我在 linq 中编写了一个查询,根据员工编号返回 10 个不同员工的信息。不过,我是使用 linq 工作的新手,但在退货时遇到了问题。我在这段代码中做错了什么?
public class queryClass
{
private string firstName { get; set; }
private string lastName { get; set; }
private int employeeNo { get; set; }
private string department { get; set; }
}
public static queryClass[] GetEmpData(int empID1, int empID2, int empID3, int empID4, int empID5, int empID6, int empID7, int empID8, int empID9, int empID10)
{
using(var context = new EmpInfoDataContext())
{
var query = from e in context.EmployeTable
join j in context.JobTitles on e.JobTitle equals j.JobTitle
where e.EmployeeNo == empID1
where e.EmployeeNo == empID2
where e.EmployeeNo == empID3
where e.EmployeeNo == empID4
where e.EmployeeNo == empID5
where e.EmployeeNo == empID6
where e.EmployeeNo == empID7
where e.EmployeeNo == empID8
where e.EmployeeNo == empID9
where e.EmployeeNo == empID10
select new {e.FirstName, e.LastName, e.EmployeeNo, j.Department};
return query.ToArray();
}
}
在“return query.Toarray();”下,错误是“无法将表达式类型 '{FirstName:string, LastName:string, EmployeeNo:int, Department:string}[] 转换为返回类型 'Employeephotos.Models.HomeModel.queryClass []"
谢谢你提供的所有帮助。