1

I have a class named Course, and a user class.

public virtual ICollection<ApplicationUser> Subscribers { get; set; }

This is what my lazy load collection of users looks like,this is a collection in the Course class.

Same goes for the User class which contains a collection of courses.

The relationship between those two is defined as it follows

modelBuilder.Entity<ApplicationUser>().HasMany(z => z.Courses).WithMany();
modelBuilder.Entity<Course>().HasMany(z => z.Subscribers).WithMany();
base.OnModelCreating(modelBuilder);

When I enter the Entity Framework tables for Course and User they do not contain any of those lists that I defined as a properties on those classes,so I cannot user them to save data in them.

Can you please tell me what the reason could be.

Sample of method

var course = db.Courses.Find(id);
var user = userManager.FindByName(User.Identity.Name);
if (!user.Courses.Contains(course))
{
    user.Courses.Add(course);
    db.SaveChanges();
    var item = db.Courses.Where(i => i.Title == course.Title);
    return Content(item.First().Title);
    ---> Verified that course is in the database.
}

After I redirect the user to his courses the list of courses is empty again.

0 Answers0