I'm using code first and fluent api this is my models public Admin() { this.course = new HashSet<Courses>(); } [Key] public int ID { get; set; } public string LoginName { get; set; } public virtual ICollection<Courses> course { get; set; } } public Courses() { this.admin = new HashSet<Admin>(); } [Key] public int ID { get; set; } public string Name { get; set; } public virtual ICollection<Admin> admin { get; set; } } and this is fluent api modelBuilder.Entity<Admin>() .HasMany(e => e.course) .WithMany(e => e.admin); and this is my controller which I'm getting the courseid from cshml public ActionResult Admins( Admin rec, IList CourseId) { foreach (var item in CourseId) { var cr = new Courses(); cr.ID = item; rec.course.Add(cr); } db.Admins.Add(rec); db.SaveChanges(); it gives me error when I'm trying to save db.SaveChanges() could any one tell me what's the wrong here ?
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)