首先只使用一个实体,当我从ASP.NET Web应用程序数据库中检索创建的员工记录时,所有实体都运行得非常顺利,它在我的程序的UWP部分中正确显示ListView上的记录
但当我添加另一个实体即'部门'时,程序开始显示此错误:prnt.sc/bogk52
我已尝试使用此代码,但无法执行此操作。如果您需要查看更多代码,请告诉我们。非常感谢。
EmployeeController
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
};
}
视图模型
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; }
}
EmployeesContext
public System.Data.Entity.DbSet<XamarinFormsDemo.Models.Employee> Employees { get; set; }
public System.Data.Entity.DbSet<XamarinFormsDemo.Models.Department> Departments { get; set; }