title: Swagger creating an extra definition for students when already in the students entity
body: <p>Right im still just as confused in ef core 5.10 I am creating a model as suggested by the new method.</p>
  <p>I have the model as.</p>
  <pre><code>modelBuilder.Entity&lt;Students&gt;().HasMany(x =&gt; x.Workouts)
    .WithMany(x =&gt; x.Students)
    .UsingEntity&lt;StudentWorkout&gt;(
     x =&gt; x.HasOne(x =&gt; x.WorkOuts)
    .WithMany().HasForeignKey(x =&gt; x.StudentId),
    x =&gt; x.HasOne(x =&gt; x.Students)
    .WithMany().HasForeignKey(x =&gt; x.WorkOutId));
  </code></pre>
  <p>This is the code I use to attach combines to students.</p>
  <pre><code> modelBuilder.Entity&lt;Students&gt;().HasMany(x =&gt; x.Combines)
  .WithMany(x =&gt; x.Students)
  .UsingEntity&lt;StudentCombines&gt;(
  x =&gt; x.HasOne(x =&gt; x.Combines)
  .WithMany().HasForeignKey(x =&gt; x.StudentId),
  x =&gt; x.HasOne(x =&gt; x.Students)
  .WithMany().HasForeignKey(x =&gt; x.CombinesId));
  </code></pre>
  <p>It created its table here fine</p>
  <p><a href="https://i.stack.imgur.com/pT3rM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pT3rM.png" alt="enter image description here" /></a></p>
  <p>What I dont get is why on earth is my swagger defination creating an extra entry for students in workouts json</p>
  <pre><code>&quot;workouts&quot;: [
    {
      &quot;workOutId&quot;: 0,
      &quot;studentId&quot;: 0,
      &quot;tb&quot;: 0,
      &quot;op&quot;: 0,
      &quot;pu&quot;: 0,
      &quot;bp&quot;: 0,
      &quot;bj&quot;: 0,
      &quot;notes&quot;: [
        {
          &quot;id&quot;: 0,
          &quot;title&quot;: &quot;string&quot;,
          &quot;shortNotes&quot;: &quot;string&quot;,
          &quot;longNotes&quot;: &quot;string&quot;,
          &quot;description&quot;: &quot;string&quot;,
          &quot;notesAccessLevel&quot;: true,
          &quot;tennantId&quot;: &quot;3fa85f64-5717-4562-b3fc-2c963f66afa6&quot;,
          &quot;isDeleted&quot;: true,
          &quot;isActive&quot;: true,
          &quot;createdBy&quot;: &quot;string&quot;,
          &quot;lastModifiedBy&quot;: &quot;string&quot;,
          &quot;lastUpdatedDate&quot;: &quot;2021-09-22T22:35:08.380Z&quot;,
          &quot;createdDate&quot;: &quot;2021-09-22T22:35:08.380Z&quot;
        }
      ],
      &quot;students&quot;: [
        &quot;string&quot;
      ],
      &quot;isBlackLevel&quot;: true,
      &quot;canEdit&quot;: true,
      &quot;ispb&quot;: true,
      &quot;isDeleted&quot;: true,
      &quot;isActive&quot;: true,
      &quot;createdBy&quot;: &quot;string&quot;,
      &quot;lastModifiedBy&quot;: &quot;string&quot;,
      &quot;lastUpdatedDate&quot;: &quot;2021-09-22T22:35:08.381Z&quot;,
      &quot;createdDate&quot;: &quot;2021-09-22T22:35:08.381Z&quot;
    }
  ],
  </code></pre>
  <p>My Workout class</p>
  <pre><code>public class Workouts
  {
      [Key]
      public int WorkOutId { get; set; }
      public int StudentId { get; set; } 
      public decimal? TB { get; set; }
      public decimal? OP { get; set; }
      public decimal? PU { get; set; }
      public decimal? BP { get; set; }
      public decimal? BJ { get; set; }        
      public ICollection&lt;Notes&gt;? Notes { get; set; }      
      public virtual ICollection&lt;Students&gt; Students { get; set; } = new List&lt;Students&gt;();
     public bool? IsBlackLevel { get; set; }
     public bool? CanEdit { get; set; }
      public bool? ISPB { get; set; }
      public bool? IsDeleted { get; set; }
      public bool? IsActive { get; set; }
      public string? CreatedBy { get; set; }  
      public string? LastModifiedBy { get; set; }
      public DateTime? LastUpdatedDate { get; set; }
      public DateTime? CreatedDate { get; set; }
  }
  </code></pre>
  <p>My Student Class I also have two others another class called Combines bscailly</p>
  <pre><code>public class Students
  {   [Key]
      public int StudentId { get; set; }
      public int? Type { get; set; }
      public string? FirstName { get; set; }
      public string? Surname { get; set; }
      public DateTime? DOB { get; set; }
      public decimal? Weight { get; set; }
      public decimal? Height { get; set; }
      public int? Gender { get; set; }
      public string? Photo { get; set; }
      public string? Age { get; set; }
      public virtual ICollection&lt;Combines&gt; Combines { get; set; }
      public virtual ICollection&lt;Workouts&gt; Workouts { get; set; }
      public virtual ICollection&lt;Classes&gt; Classes { get; set; }
      public bool? IsDeleted { get; set; }
      public ICollection&lt;Notes&gt;? Notes { get; set; }
      public decimal? TB { get; set; }
      public decimal? OP { get; set; }
      public decimal? PU { get; set; }
      public decimal? PB { get; set; }
      public decimal? BP { get; set; }   
      public bool? IsActive { get; set; }
      public string? CreatedBy { get; set; }
      public string? LastModifiedBy { get; set; }
      public DateTime? LastUpdatedDate { get; set; }
      public DateTime? CreatedDate { get; set; }
  }
  </code></pre>
  <p>My Quesiton is do i need to add json ignore to stop this being output via swagger?.
  Under the workout json as you see. Am already in the students json so why would I need to get them again.</p>
  <p>&quot;students&quot;: [
  &quot;string&quot;
  ],</p>
  <p>In my Api Controlers</p>
  <p>The two functions that use students look like this.</p>
  <pre><code>public List&lt;Students&gt; GetAllStudents()
  {
     return db.Students.Where(w =&gt; w.IsActive == true &amp;&amp; w.IsDeleted == false).Include(i =&gt; i.Notes).Include(i =&gt; i.Classes).Include(i =&gt; i.Workouts).Include(I=&gt;I.Combines).ToList();
  }
  
  public Students GetStudentById(int StudentId)
  {
   return db.Students.Where(w =&gt;w.StudentId== StudentId &amp;&amp; w.IsActive == true &amp;&amp; w.IsDeleted == false).Include(i =&gt; i.Notes).Include(i=&gt;i.Classes).Include(i =&gt; i.Workouts).Include(I =&gt; I.Combines).FirstOrDefault();
  }
  </code></pre>
  <p>I simply want One Student to Many , Workouts , Classes and Combines</p>
  <p>My json is screwed up as well returning students. in amongst the workout when it should just be the workouts :-(.</p>
  <p>As Far as I can tell by the docs you still need this in EF5.10</p>
  <pre><code>public class StudentWorkout
  {
      public int StudentId { get; set; }       
      public int WorkOutId { get; set; }
      //You can add extra properties here
      //relationships
      public Students Students { get; set; }
      public Workouts WorkOuts { get;  set; }
  }
  </code></pre>
  <p>In that table I have the following</p>
  <p><a href="https://i.stack.imgur.com/EP2Xr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EP2Xr.png" alt="enter image description here" /></a></p>
  <p>Which should give me 1 student with 2 work outs in the jason response but its not.</p>
  <p>As per this data.</p>
  <p><a href="https://i.stack.imgur.com/TI4dl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TI4dl.png" alt="enter image description here" /></a></p>
  <p><strong>Edit 2</strong>
  Ok I found my issue with the data mapping</p>
  <p>I found my answer I had the id's the wrong way round in the on creating segment so it was obv using the workout ids for the person instead of the actual column was meant to use.</p>
  <pre><code>modelBuilder.Entity&lt;Students&gt;().HasMany(x =&gt; x.Workouts)
  .WithMany(x =&gt; x.Students)
  .UsingEntity&lt;StudentWorkout&gt;(
   x =&gt; x.HasOne(x =&gt; x.WorkOuts)
   .WithMany().HasForeignKey(x =&gt; x.WorkOutId),
   x =&gt; x.HasOne(x =&gt; x.Students)
   .WithMany().HasForeignKey(x =&gt; x.StudentId));
  
  
   modelBuilder.Entity&lt;Students&gt;().HasMany(x =&gt; x.Combines)
   .WithMany(x =&gt; x.Students)
   .UsingEntity&lt;StudentCombines&gt;(
    x =&gt; x.HasOne(x =&gt; x.Combines)
   .WithMany().HasForeignKey(x =&gt; x.CombinesId),
   x =&gt; x.HasOne(x =&gt; x.Students)
   .WithMany().HasForeignKey(x =&gt; x.StudentId));
  </code></pre>
  <p>I had them wrong way round here but still does not explain the extra students in the workout bit.</p>