title: EF Core incorrectly doing multiple inserts for Array
body: <p>I'm still new with Entity Framework and I'm struggling with an issue while inserting records to the database on .NET Core API service I'm developing.</p>
  <p>Summarizing what is going on, I'm not generating the schema from EF, instead I create the tables in SQL and just have EF access it.</p>
  <p>I have a model objects similar to this:</p>
  <pre><code>[Table(&quot;events&quot;)]
  public class Event
  {
      [Key]
      [Required]
      [Column(&quot;id&quot;)]
      public Guid Id { get; set; }
  
      public string EventName { get; set; }
  
      public List&lt;Session&gt; Sessions { get; set; }
  }
  
  [Table(&quot;sessions&quot;)]
  public class Session
  {
      [Key]
      [ForeignKey(&quot;FK_events-sessions&quot;)]
      [Column(&quot;eventId&quot;)]
      public Guid EventId { get; set; }
  
      public byte Hour { get; set; }
  
      public byte Day { get; set; }
  
      public byte Month { get; set; }
  }
  </code></pre>
  <p>Other then this, on the context class, I declare a one to many relationship:
  <code>modelBuilder.Entity&lt;Event&gt;().HasMany(s =&gt; s.Sessions);</code></p>
  <p>In the SQL DB, the table columns have matching names, but all start with lowercase letters.</p>
  <p>The issue I'm having is that when I perform the POST operation, where an <code>Event</code> object with multiple session is added and saved, it throws an error:</p>
  <blockquote>
  <p>Microsoft.EntityFrameworkCore.DbUpdateException: An error occurred while saving the entity changes. See the inner exception for details.
  ---&gt; Microsoft.Data.SqlClient.SqlException (0x80131904): The column name 'eventId' is specified more than once in the SET clause or column list of an INSERT. A column cannot be assigned more than one value in the same clause. Modify the clause to make sure that a column is updated only once. If this statement updates or inserts columns into a view, column aliasing can conceal the duplication in your code.</p>
  </blockquote>
  <p>I've enabled Information logging on EF and I see it doing this:</p>
  <pre><code>INSERT INTO [sessions] ([eventId], [Hour], [Day], [EventId], [Month])
  VALUES (@p0, @p1, @p2, @p3, @p4);
        INSERT INTO [sessions] ([eventId], [Hour], [Day], [EventId], [Month])
        VALUES (@p0, @p1, @p2, @p3, @p4);
  </code></pre>
  <p>As you can see, it's adding the Id column twice for some reason.
  I wonder if the first one is my mapping that I annotate with <code>[Column(&quot;eventId&quot;)]</code> and the other one a generated one from the object <code>Event</code>.</p>
  <p>Any idea?</p>
  <p>Thank you.</p>