My aim is to display data from two tables in my HTML page in one table/grid.
ID, Forename, Surname, Hobby Name
Tables
People(ID, Forename, Surname, Hobby ID)
Hobby(ID, Hobby Name)
namespace DC.ViewModels
{
public class PeopleHobbyView()
{
public int ID {get; set;}
public string Forename {get; set;}
public string Surname {get; set;}
public string Hobby_Name {get; set;}
}
public class PeopleHobbiesVM
{
public List<PeopleHobbyView> PeopleList { get; set; }
public void GetPeople()
{
using (var context = new LSF1617Entities())
{
var people = (from people in context.People join hobbies in context.Hobby on people.Hobby_ID equals hobbies.ID
select new PeopleHobbyView { ID = people.ID, Forename = people.Forename, Surname = people.Surname, Hobby_Name = hobbies.Hobby_Name}
);
this.PeopleList = people.ToList();
}
}
}
}
Hobby name has to be of course looked up in the Hobby table, so I have created a join in my GetPeople()
method
This all seems a bit long winded, I just wanted to get reassurance that this is a good way of going about the task. I have read a bit about lazy/eager loading, and I can't seem to get my head around it completely.