The asp.net core application. The following list of models is available:

public class Year { public int Id { get; set; } public string Name { get; set; } // ex. 2014-2015, 2018-2019 public bool IsSemestr { get; set; } public int PartOfYear { get; set; } public List<Group> Groups { get; set; } } public class Group { public int Id { get; set; } public string NameGroup { get; set; } public virtual List<Student> Students { get; set; } } public class Student { public int Id { get; set; } public string Name { get; set; } public bool Debt { get; set; } public virtual List<Subject> Subjects { get; set; } } public class Subject { public int Id { get; set; } public string Name { get; set; } public string ExamType { get; set; } public double Credits { get; set; } public double Hours { get; set; } public string Lecture { get; set; } public int Score { get; set; } public string DateDebt { get; set; } } 

And also the following database context:

 public class UniversityContext : DbContext { public DbSet<Year> Years { get; set; } public UniversityContext(DbContextOptions<UniversityContext> options) : base(options) { Database.EnsureCreated(); } } 

The name of the student who needs to be found in the database is transferred to the controller. And then there is a problem. The data in the database is present, I looked in the SQL browser, but they are not loaded, only the Year class is loaded, and all other nested collections are null. How to fix the problem, I pull up the data from the database in the controller with the following code:

  public string Get(string discipline, string student, string group, string time) { if(student != null) { IEnumerable<Year> fYear = context.Years; View("byName.cshtml", fYear.First().Groups[0].Students[0]); } return "hi"; } 

Groups == null although there are 35 of them.

  • 2
    For a lazy load to work, the property must be marked virtual . - Alexander Petrov
  • I marked and still does not work. - Once Two
  • one
    in the presented code, the Groups property of the class Year not marked as virtual - Anatol

0