ok, i have to admit that until now i still do not know the best way to return multiple objects using linq to sql.
public IList<Course> GetAllStudentCourses()
{
IList<Course> output = new List<Course>();
using (lenDataContext db = new lenDataContext())
{
var result =
from ct in db.CourseByTutors
join c in db.Courses on ct.CourseId equals c.Id
join u in db.Users on ct.TutorId equals u.Id
select new
{
c,
u,
};
foreach (var r in result)
{
Course course = new Course();
course.CourseByTutor = new CourseByTutor();
course = r.c;
course.IsGroupString = (r.c.IsGroup == 1) ? "Yes" : "No";
course.User = r.u;
output.Add(course);
}
}
return output;
}
I would like to return Course and User objects back to UI.
private void InitializeData()
{
Course c = new Course();
dgCourses.AutoGenerateColumns = false;
bs.DataSource = c.GetAllStudentCourses().ToList();
dgCourses.DataSource = bs; //bs is bindingsource
}
How do i display the user data e.g. Name to the Gridview? i have put User.Name to the datapropertyName but it still showing nothing. my Course.User has value.