title: EntityFramework Mutli-Table Many-to-Many
body: <p>I'm working with EF4.1 Code First and am trying to create some Many-to-Many relationship tables where there tables would need to be linked. Please see small snippet of code beloow:</p>
  
  <pre><code>class Event
  {
      int EventId { get; set; }
      ICollection&lt;Contact&gt; Contacts { get; set; }
  }
  
  class Contact
  {
      int ContactId { get; set; }
      ICollection&lt;Relation&gt; Relations { get; set; }
  }
  
  class Relation
  {
      int RelationId { get; set; }
      string Name { get; set; }
  }   
  </code></pre>
  
  <p>So the Contacts object can have many different types of Relationship, such as "Mother", "Father", "Brother", etc.</p>
  
  <p><strong>I need to track some kind of Event where a Contact attended, but I want to know how he is related to the person hosting the Event. So for example, was he the Eventer's Brother, Father or Husband? At another event, the same person could show up, but be the Eventer's Brother-in-Law.</strong></p>
  
  <p>Event to Contact is Many-to-Many; Relation to Contact is One-to-Many.</p>
  
  <p>In SQL, we would just made a link table and have all three properties Id's there (EventId, ContactId, RelationId); however, in Code First, <strong>how would you represent this relationship?</strong></p>