问题
Good Day everyone. I'm currently creating a simple Xamarin.Forms Portable mobile application that allows me to input record of an Employee Name and Employee Department.
I was able to retrieve the employee records created from the ASP.NET Web application Database, and display it on a ListView in the UWP part of my program. However, the data being retrieved is just coming from a single Entity namely 'Employee'. How will I display records that comes from 2 different Entities?
I have tried it using this codes but wasn't able to do so. If you need to see more codes, just please let me know. Thanks a lot.
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
};
}
ViewModel
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; }
来源:https://stackoverflow.com/questions/38158014/xamarin-forms-portable-how-to-display-data-that-comes-from-2-different-entitie