我能够检索从ASP.NET Web应用程序数据库创建的员工记录,并将其显示在程序的UWP部分的ListView中。但是,检索的数据只来自单个实体,即“员工”。如何显示来自2个不同实体的记录?
我已尝试使用此代码,但无法执行此操作。如果您需要查看更多代码,请告诉我们。非常感谢。
EmployeeController
<form id="form1" onsubmit="return false">
<button id="btn1" onclick="clicked();">Submit</button>
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
视图模型
private EmployeesContext db = new EmployeesContext();
public IQueryable<EmployeeVM> GetEmployees()
{
return from emp in db.Employees
join dept in db.Departments
on emp.Department_id equals dept.Id
select new EmployeeVM
{
Id = emp.Id,
Name = emp.Name,
Department_id = emp.Department_id,
Department_Name = dept.Department_Name
};
}
EmployeesContext
public class EmployeeVM
{
public int Id { get; set; }
public string Name { get; set; }
//public string Department { get; set; }
public int Department_id { get; set; }
public string Department_Name { get; set; }
}