title: ASP.NET MVC3 EF Code First - Many-to-many relationships
body: <p>I'm trying to create a many-to-many relationship using EF code first in my MVC project. I have a scenario where I have a Service which can have many Categories which may have many subcategories. This bit seems to be working fine.</p>
  
  <p>Each Service, Category and Subcategory can also have many HelpDeskMembers associated with it. This is where I'm having trouble creating the association. With the classes below I was expecting EF to create Service_HelpDeskMembers, Category_HelpDeskMembers and Subcategory_HelpDeskMembers tables. Please can somebody guide me in the right direction?</p>
  
  <p><em>P.S. In the navigation properties, I am not using virtual because I am using AJAX and JSON to create cascading drop down lists between Service/Category/Subcategory and by using 'virtual', I was getting a circular reference error.</em></p>
  
  <p>Here are my classes.</p>
  
  <pre><code>public class Service
  {
      [Key]
      public int ServiceID { get; set; }
  
      public string Title { get; set; }
      public DateTime CreatedDate { get; set; }
      public HelpDeskMember CreatedBy { get; set; }
      public DateTime? DeletedDate { get; set; }
      public HelpDeskMember DeletedBy { get; set; }
  
      public ICollection&lt;Category&gt; Categories { get; set; }
      public ICollection&lt;HelpDeskMember&gt; LinesOfSupport { get; set; }
  }
  
  public class Category
  {
      [Key]
      public int CategoryID { get; set; }
      [ForeignKey("Service")]
      public int ServiceID { get; set; }
  
      public string Title { get; set; }
      public DateTime CreatedDate { get; set; }
      public HelpDeskMember CreatedBy { get; set; }
      public DateTime? DeletedDate { get; set; }
      public HelpDeskMember DeletedBy { get; set; }
  
      public Service Service { get; set; }
      public ICollection&lt;Subcategory&gt; Subcategories { get; set; }
      public ICollection&lt;HelpDeskMember&gt; LinesOfSupport { get; set; }
  }
  
  public class Subcategory
  {
      [Key]
      public int SubcategoryID { get; set; }
      [ForeignKey("Category")]
      public int CategoryID { get; set; }
  
      public string Title { get; set; }
      public DateTime CreatedDate { get; set; }
      public HelpDeskMember CreatedBy { get; set; }
      public DateTime? DeletedDate { get; set; }
      public HelpDeskMember DeletedBy { get; set; }
  
      public Category Category { get; set; }
      public ICollection&lt;HelpDeskMember&gt; LinesOfSupport { get; set; }       
  }
  
  public class HelpDeskMember
  {
      public int HelpDeskMemberID { get; set; }
      public string Name { get; set; }
      public bool Admin { get; set; }
      public bool Available { get; set; }
      public DateTime? CreatedDate { get; set; }
      public DateTime? LastLogin { get; set; }
      public DateTime? DeletedDate { get; set; }
      public DateTime? DeletedBy { get; set; }
  
      public ICollection&lt;Service&gt; Services { get; set; }
      public ICollection&lt;Category&gt; Categories { get; set; }
      public ICollection&lt;Subcategory&gt; Subcategories { get; set; }
  }
  </code></pre>
  
  <p>Thanks in advance.</p>