title: Entity Framework 4 CTP 5 POCO - Many-to-many configuration, insertion, and update?
body: <p>I really need someone to help me to fully understand how to do many-to-many relationship with Entity Framework 4 CTP 5, POCO. I need to understand 3 concepts:</p>
  
  <ol>
  <li>How to config my model to indicates
  some tables are many-to-many.</li>
  <li>How to properly do insert.</li>
  <li>How to properly do update.</li>
  </ol>
  
  <p>Here are my current models:</p>
  
  <pre><code>public class MusicSheet
  {
      [Key]
      public int ID { get; set; }
      public string Title { get; set; }
      public string Key { get; set; }
  
      public virtual ICollection&lt;Author&gt; Authors { get; set; }
      public virtual ICollection&lt;Tag&gt; Tags { get; set; }
  }
  
  public class Author
  {
      [Key]
      public int ID { get; set; }
      public string Name { get; set; }
      public string Bio { get; set; }
  
      public virtual ICollection&lt;MusicSheet&gt; MusicSheets { get; set; }
  }
  
  public class Tag
  {
      [Key]
      public int ID { get; set; }
      public string TagName { get; set; }
  
      public virtual ICollection&lt;MusicSheet&gt; MusicSheets { get; set; }
  }
  </code></pre>
  
  <p>As you can see, the <code>MusicSheet</code> can have many <code>Authors</code> or <code>Tags</code>, and an <code>Author</code> or <code>Tag</code> can have multiple <code>MusicSheets</code>.</p>
  
  <p>Again, my questions are:</p>
  
  <ol>
  <li>What to do on the
  <code>EntityTypeConfiguration</code> to set the
  relationship between them as well as
  mapping to an table/object that
  associates with the many-to-many
  relationship.</li>
  <li>How to insert a new music sheets
  (where it might have multiple
  authors or multiple tags).</li>
  <li>How to update a music sheet. For
  example, I might set <strong>TagA</strong>,
  <strong>TagB</strong> to MusicSheet1, but later I need to change the tags to <strong>TagA</strong>
  and <strong><em>TagC</em></strong>. It seems like I need
  to first check to see if the tags
  already exists, if not, insert the
  new tag and then associate it with
  the music sheet (so that I doesn't
  re-insert <strong>TagA</strong>?). Or this is
  something already handled by the
  framework?</li>
  </ol>
  
  <p>Thank you very much. I really hope to fully understand it rather than just doing it without fully understand what's going on. Especially on #3.</p>