dept_name emp_name email
HR AAAA aa@aa.com
Payroll BBAA aa@aa.com
该怎么做
提前致谢
答案 0 :(得分:0)
在你的每个循环中删除dep_id并使用dept_name(假设你的员工类有dept_name)
public class employee {
public string emp_name {get;set;}
public string email {get;set;}
public int emp_id {get;set;}
public int dept_id {get;set;}
public string dept_name {get;set;}
}
var query = (from x in sa.employee
join y in sa.dept on x.dept_id equals y.dept_id
where y.dept_id == x.dept_id
select new { x.emp_id, x.emp_name, x.email, y.dept_id, y.dept_Name }).ToList();
var empdtls = new List<employee>();
foreach (var t in query)
{
empdtls.Add(new employee() { emp_name = t.emp_name, email = t.email,emp_id=t.emp_id,dept_name=t.dept_name });
}
return View(empdtls)