示例#1
0
        public Student GetEnrollments(int studentId)
        {
            var student = _context.Students.Find(studentId);

            if (student != null)
            {
                _context.Entry(student).Collection(s => s.Enrollments)
                .Query().Include(e => e.Unit).Load();
            }
            return(student);
        }
示例#2
0
        public Unit GetUnit(int id)
        {
            var unit = _context.Units.Find(id);

            if (unit != null)
            {
                // explicit loading (kind of)
                // source: https://stackoverflow.com/a/41535211/344162
                _context.Entry(unit).Collection(u => u.Enrollments)
                .Query().Include(e => e.Student).Load();
            }
            return(unit);
        }