title: How express the many to many relationship with single parent table in EF 5
body: <p>I have something like a Department, which can have many courses and students. students can be linked to many courses and courses could have many students registered to it. I also want student and courses to be linked to a department.</p>
  
  <p>How can i express this in EF/Fluent API, I have tried these </p>
  
  <pre><code>        modelBuilder.Entity&lt;Student&gt;().HasRequired(s =&gt; s.Department);
          modelBuilder.Entity&lt;Course&gt;().HasRequired(u =&gt; u.Department);
  
          modelBuilder.Entity&lt;Course&gt;()
                      .HasMany(s =&gt; s.Students)
                      .WithOptional()
                      .WillCascadeOnDelete(false);
          modelBuilder.Entity&lt;Course&gt;()
                      .HasMany(u =&gt; u.Students)
                      .WithMany(s =&gt; s.Courses);
          modelBuilder.Entity&lt;Student&gt;()
                      .HasMany(s =&gt; s.Courses)
                      .WithOptional()
                      .WillCascadeOnDelete(false);
  </code></pre>
  
  <p>and I tried few other combinations as well, nothing worked and I get this error now</p>
  
  <pre><code>The navigation property 'Courses' declared on type 'Models.Student' has been configured with conflicting multiplicities.
  </code></pre>
  
  <p>Any hints/ help?</p>
  
  <p>Update: The student class looks like this</p>
  
  <pre><code>public class Student
  {
      [Key]
      public string Id { get; set; }
  
      [Required]
      public string SiteName { get; set; }
  
      public virtual Department Department { get; set; }
  
      public virtual ICollection&lt;Course&gt; Courses { get; set; }
  }
  </code></pre>
  
  <p>and the Course:</p>
  
  <pre><code>    public class Course
  {
      [Key]
      public string Id { get; set; }
  
      [Required]
      public string Name { get; set; }
  
  
      public virtual Department Department { get; set; }
  
      public virtual ICollection&lt;Student&gt; Students { get; set; }
  
  }
  </code></pre>