Because Include does not bring the users with whom it is related, only the accounts


Good day I currently have three tables for the subject (Subject), user and the relation materia_usuario (Enroll_Teacher_Subject). I am making a query in the controller in which I want to show me the subject and the relations with the table materia_usuario. When I make the query it brings the data of the table material well but when it brings the information of the table materia_usuario it only brings me the amount of relationships that exist and I want to show me the information in detail. I want to show this information on a page that receives the subject model

this is the table matter

public class Subject
    public int SubjectId { get; set; }

    [StringLength(50)]//only you can to write 50 characters
    [Display(Name = "Nombre de la Materia")]
    public string NameSubject { get; set; }

    [Display(Name = "Descripcion de la Materia")]
    public string DescriptionSubject { get; set; }

    [Display(Name = "Grado")]
    public int LevelId { get; set; }

    public virtual Level Level { get; set; }

    public virtual ICollection<Enroll_Teacher_Subject> Enroll_Teacher_Subjects { get; set; }

The table relacion usuario_materia

public class Enroll_Teacher_Subject
    public int Enroll_Teacher_SubjectId { get; set; }

    [Display(Name = "Fecha Matricula ")]
    public DateTime DateEnroll_Teacher_Subject { get; set; }

    [Display(Name = "Observaciones")]
    public string ObservationEnroll_Teacher_Subject { get; set; }

    [Display(Name = "Profesor")]
    public int UserId { get; set; }

    public virtual UserSchool UserSchool { get; set; }

    [Display(Name = "Materia")]
    public int SubjectId { get; set; }

    public virtual Subject Subject { get; set; }

    [Display(Name = "Anno lectivo")]
    public int AnnoLectivoId { get; set; }
    public virtual AnnoLectivo AnnoLectivo { get; set; }

    public virtual ICollection<Enroll_Student_Subject_Teacher> Enroll_Student_Subject_Teachers { get; set; }


This is the driver where I want to ask the question

public async Task<ActionResult> Details(int? id)
        if (id == null)
            return new HttpStatusCodeResult(HttpStatusCode.BadRequest);

        var SubjectList = await db.Subjects
                                        .Include(x => x.Enroll_Teacher_Subjects)                                            
                                        .FirstOrDefaultAsync(x => x.SubjectId == 5);

        if (SubjectList == null)
            return HttpNotFound();

        return View(SubjectList);


The error that I refer to is this

asked by Jhon Alexander Jimenez Morales 19.11.2018 в 15:41

0 answers