LINQ Query to get Student Classes

[System.Web.Http.Route("api/data/StudentClasses")]
public IEnumerable<Student> GetStudentClasses() {
    var db = new School_DBEntities();
    var xx = db.Students.ToList().Select(q=>new Student()
    { 
        Student_ID=q.Student_ID,
        First_Name=q.First_Name,
        Classes=q.StudentsClasses.ToList().Select(e=>new Class()
        {
            Class_code=e.Class,
            Class_Name=db.Classes.FirstOrDefault(v=>v.Class_code==e.Class).Class_Name
        }).ToList()
    });
   
    return xx;
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top