title: Ignore duplicate entries and commit successful ones on DbContext.SaveChanges() in EF Core
body: <p>I have an ASP .Net Core 2.2 Web API. In one of my controller actions, I am adding a bunch of rows to a MySQL database table (I'm using Pomelo).</p>
  
  <p>So for example:</p>
  
  <pre><code>_dbContext.AddRange(entities);
  _dbContext.SaveChanges();
  </code></pre>
  
  <p>The entities I'm adding have two primary keys (composite primary key) and the keys are already populated in the entities collection when I add them to DbContext (i.e. I am setting the keys myself - there is no "auto increment" or anything like that where the database generates the keys)</p>
  
  <p>If any of the entities I'm adding already exist in the database, in terms of a duplicate primary key, then obviously SaveChanges() throws an exception, and the entire transaction rolls back.</p>
  
  <p>Is there a way to tell EF Core to ignore the entities that failed? i.e. to ignore the entities that already existed in the database, and commit the entities that succeeded (i.e. that did not exist in the database)? Instead of the current behaviour which is to throw an exception and roll back the entire transaction?</p>
  
  <p>Thanks</p>