title: ASP.NET Core 2.2 returns "NotSupportedException: Collection was of a fixed size" on Many-to-Many insert
body: <p>I got <strong>"NotSupportedException: Collection was of a fixed size"</strong> when I try to insert into the linking table in <strong>Many-to-Many</strong> in <strong>ASP.NET Core 2.2</strong>.
  I can insert values manually in SQL Server!</p>
  
  <p>My entities are:</p>
  
  <pre><code>    public class Product
      {
          [key]
          public int Id {get;set;}
  
          public ICollection&lt;ProductCategory&gt; ProductCategories { get; set; } = new List&lt;ProductCategory&gt;();
      }
  </code></pre>
  
  <pre><code>    public class Category
      {
          [key]
          public int Id {get;set;}
  
          public string Name { get; set; }
  
          public ICollection&lt;ProductCategory&gt; ProductCategories { get; set; } = new List&lt;ProductCategory&gt;();
  
      }
  </code></pre>
  
  <pre><code>    public class ProductCategory
      {
          [Key]
          public int ProductId { get; set; }
          public Product Product { get; set; }
  
          [Key]
          public int CategoryId { get; set; }
          public Category Category { get; set; }
      }
  </code></pre>
  
  <p>in DbContext:</p>
  
  <pre><code>        protected override void OnModelCreating(ModelBuilder modelBuilder)
          {
  
              modelBuilder.Entity&lt;ProductCategory&gt;().HasKey(t =&gt; new { t.ProductId, t.CategoryId });
  
  
              modelBuilder.Entity&lt;ProductCategory&gt;()
                  .HasOne(bc =&gt; bc.Product)
                  .WithMany(b =&gt; b.ProductCategories)
                  .HasForeignKey(bc =&gt; bc.ProductId);
  
              modelBuilder.Entity&lt;ProductCategory&gt;()
                  .HasOne(bc =&gt; bc.Category)
                  .WithMany(c =&gt; c.ProductCategories)
                  .HasForeignKey(bc =&gt; bc.CategoryId);
  
              base.OnModelCreating(modelBuilder);
          }
  
          public DbSet&lt;Product&gt; Products { get; set; }
          public DbSet&lt;Category&gt; Categories { get; set; }
          public DbSet&lt;ProductCategory&gt; ProductCategories {get; set;}
  </code></pre>
  
  <p>I tries to insert records to Product and Category, The records inserted with no problem.
  But as soon as I try to insert linking records I got <strong>"NotSupportedException: Collection was of a fixed size"</strong> error.</p>
  
  <p>Inserting :</p>
  
  <pre><code>            var Electronics = new Category
              {
                  Name = "Electronics",
              };
  
              var Exir = new Product
              {
                  Name = "Exir",
              };
  
              var pc1 = new ProductCategory();
  
              bc1.Product = Exir ;
              bc1.Category = Electronics;
              Exir.ProductCategories.Add(pc1);
  
              sqlContext.Categories.Add(Electronics);
              sqlContext.Products.Add(Exir);
              sqlContext.SaveChanges();
  </code></pre>