I am learning EF6 with MVC 5 following this tutorial. I understand this question may have been asked, however I am not sure what exactly I need to be looking for? I checked the db and data is in there? Can anyone point me in the right direction?
I have an issue where in my Model.Enrollments is null(this view takes a student model), however in the database it shows it has values in that table.
Model: Student
public int ID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public ICollection<Enrollment> Enrollments { get; set; }
Course
public int ID { get; set; }
public string Title { get; set; }
public int Credits { get; set; }
public ICollection<Enrollment> Enrollments { get; set; }
Enrollment
public int ID { get; set; }
public decimal? Grade { get; set; }
public int StudentID { get; set; }
public int CourseID { get; set; }
public Student Student { get; set; }
public Course Course { get; set; }
Exception:
An exception of type 'System.NullReferenceException' occurred in App_Web_uycs14gs.dll but was not handled in user code
Additional information: Object reference not set to an instance of an object.
Update- Context
public DbSet<Student> Students { get; set; }
public DbSet<Course> Courses { get; set; }
public DbSet<Enrollment> Enrollments { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();