public TeacherDialogViewModel GetTeacherDialogData(string teacherId) { var teacher = Repositories.Teachers.Query() .AsNoTracking() .Include(t => t.User) .Include(t => t.Subjects) .ThenInclude(s => s.Subject) .ProjectTo <TeacherDialogViewModel>(Mapper.ConfigurationProvider) .FirstOrDefault(t => t.SchoolUserId == teacherId); var grade = Repositories.Classes.Query() .AsNoTracking() .Include(c => c.ClassTeacher) .ThenInclude(ct => ct.School) .Where(c => c.ClassTeacher.Id == teacherId) .ProjectTo <string>(Mapper.ConfigurationProvider) .FirstOrDefault(); if (grade is null) { teacher.Grade = "-"; } teacher.Grade = grade; teacher.AvgScore = StatisticalService.TeacherAverageScore(teacherId); return(teacher); }