title: Inserting into association table (ASP.NET MVC)
body: <p>I am writing my first ASP.NET MVC project, and very inexperienced in this subject so please bear with me. </p>
  
  <p>I have to use an existing database for a new application I need to build. I have set this up as a datasource, and used the ADO.NET Entity Data Model to select the tables I need. I have one table that holds categories associated with a parent record, joined by a unique ID. This table doesn't appear in the designer but comes the Associations folder. How do I insert records into this table? Or am I going about this completely wrong?</p>
  
  <p>Here is the code I have so far for Create:</p>
  
  <pre><code>//
  // POST: /Home/Create
  [AcceptVerbs(HttpVerbs.Post)]
  public ActionResult Create([Bind(Exclude = "KeyID")] KeyDate dateToCreate, int topic, int level, int subject, int audience)
  {
      dateToCreate.Created = DateTime.Now;
      dateToCreate.CreatedBy = User.Identity.Name;
  
      if (!ModelState.IsValid)
          return View();
  
      keyDateRepository.Add(dateToCreate);
      keyDateRepository.Save();
  
      return RedirectToAction("Index");
  }
  </code></pre>
  
  <p>Here's the code for the repository:</p>
  
  <pre><code>//
  // Insert/Delete Methods
  
  public void Add(KeyDate keyDate)
  {
     db.KeyDates.AddObject(keyDate);
  }
  
  [...]
  
  //
  // Persistence
  
  public void Save()
  {
      db.SaveChanges();
  }
  </code></pre>
  
  <p>Any help much appreciated.</p>