Xamarin.Forms.Portable : How to display data that comes from 2 different Entities?

≡放荡痞女 提交于 2020-01-17 04:44:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!