title: Insert record in many-to-many when key is DatabaseGeneratedOption.None
body: <p>I have two tables with many-to-many relation: <br/>
  <em><strong>Employee</strong></em></p>
  <pre><code>public class Employee
  {
    public int Id{ get; set; }
    public string EmployeeFirstName { get; set; }
    public string EmployeeLastName{ get; set; }
    .....
    public ICollection&lt;EmployeeSupplier&gt; EmployeeSuppliers { get; set; }
  }
  </code></pre>
  <p><em><strong>Supplier</strong></em></p>
  <pre><code>public class Supplier
  {
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.None)]
    public int Id{ get; set; }
    public string SupplierFirstName{ get; set; }
    public string SupplierLastName{ get; set; }
    .....
    public ICollection&lt;EmployeeSupplier&gt; EmployeeSuppliers { get; set; }
  }
  </code></pre>
  <p>The third model represent the table between Employee and Supplier
  <em><strong>EmployeeSupplier</strong></em></p>
  <pre><code>public class EmployeeSupplier
  {
      public int EmployeesId { get; set; }
      [ForeignKey(&quot;EmployeesId&quot;)]
      public Employee Employee { get; set; }
      public int SuppliersId { get; set; }
      [ForeignKey(&quot;SuppliersId&quot;)]
      public Supplier Supplier { get; set; }
      //Extra fieleds
      .....
  }
  </code></pre>
  <p>I create a new record of EmployeeSupplier like this:</p>
  <pre><code> var employeeSupplier = new EmployeeSupplier
              {
                  Employee = new Employee
                  {
                      EmployeeFirstName= &quot;test&quot;,
                      EmployeeLastName = &quot;test&quot;
                      .....
                  },
                  Supplier = new Supplier
                  {
                      Id = 123456, // I have to assign the value here from another source
                      SupplierFirstName= &quot;test&quot;,
                      SupplierLastName = &quot;test&quot;
                  },
                  SuppliersId= 123456
              };
  </code></pre>
  <p>Then call the <code>api</code>:</p>
  <pre><code>await HttpClient.CreateJsonAsync(&quot;/api/EmployeeSuppliers&quot;, employeeSupplier);
  </code></pre>
  <p><em><strong>Error</strong></em>:</p>
  <blockquote>
  <p>The INSERT statement conflicted with the FOREIGN KEY constraint &quot;FK_EmployeeSuppliers_Suppliers_SuppliersId&quot;. The conflict occurred in database &quot;TestDatabase&quot;, table &quot;dbo.Suppliers&quot;, column 'Id'.
  The statement has been terminated.</p>
  </blockquote>
  <p><em><strong>My questions</strong></em></p>
  <ol>
  <li>How can I create a record in  <code>EmployeeSupplier</code> table and in the same time create a new item in <code>Employee</code> table and <code>Supplier</code> table?</li>
  <li>Is  <code>DatabaseGeneratedOption.None</code> in <code>Supplier</code> table related with this error?.</li>
  <li>If <code>DatabaseGeneratedOption.None</code> doesn't relate with this error then why I didn't get the same error in FOREIGN KEY constraint <code>FK_EmployeeSuppliers_Employees_EmployeesId</code></li>
  </ol>