Note that there are some explanatory texts on larger screens.

plurals
  1. POupdating many-to-many relationships in asp.net mvc2 using entity framework 4.0 problem
    primarykey
    data
    text
    <p>Can some one point out what I am doing wrong. I went through all related questioin on this site, but I think my problem is more with MYSQL, As the error mentioned.The problem is when I try to update a relationship between two tables using EF in asp.net mvc2.</p> <p>I have these tables and I am using MYSQL.</p> <p>Course</p> <pre><code>+------------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+------------------+------+-----+---------+----------------+ | courseid | int(10) unsigned | NO | PRI | NULL | auto_increment | | coursename | varchar(100) | YES | | NULL | | +------------+------------------+------+-----+---------+----------------+ </code></pre> <p>Faculty:</p> <pre><code>+-----------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------+------------------+------+-----+---------+----------------+ | facultyid | int(10) unsigned | NO | PRI | NULL | auto_increment | | firstname | varchar(100) | YES | | NULL | | | lastname | varchar(100) | YES | | NULL | | +-----------+------------------+------+-----+---------+----------------+ </code></pre> <p>And I have this table to create the relationship</p> <pre><code>+-----------+------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+------------------+------+-----+---------+-------+ | courseid | int(10) unsigned | NO | MUL | NULL | | | facultyid | int(10) unsigned | NO | MUL | NULL | | +-----------+------------------+------+-----+---------+-------+ </code></pre> <p>Now when I want to associate a course to a faculty, both the course and faculty are existing, using the code below I got a MYSQL error: Below</p> <pre><code>[AcceptVerbs("POST")] public ActionResult AddCourse(int id, FormCollection collection) { //I made this static values for debuging Course course = scheduleEnt.Courses1.First(p =&gt; p.courseid == 5); //existing course Faculty faculty = scheduleEnt.Faculties1.First(p =&gt; p.facultyid == 1); //existing faculty faculty.courses.Add(course); UpdateModel(faculty); scheduleEnt.SaveChanges();//This is where the error generated var cc = 5; return RedirectToAction("AddCourse", new { cid = cc }); } </code></pre> <p>This is the error:</p> <pre><code>You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(SELECT `course_faculty`.`courseid`, `course_faculty`.`facultyid` ' at line 1 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload