title: Entity framework core throwing error while inserting rows in partitioned table
body: <p>I have tried using entity framework core for my project.</p>
  <p>I'm using latest PostgreSQL. And my requirement is to insert bulk data in database, which has a main table and its partitioned tables (horizontal partition).</p>
  <p>Partitioned table are inherited from the main table and gets created in advance automatically using database triggers.</p>
  <p>PostgreSQL has one more trigger like when the data for insertion arrives it decides in which partition table it has to insert using pre-decided column value.</p>
  <p>(lets say there is column of timestamp and it decides according to date).</p>
  <p><a href="https://i.stack.imgur.com/jKFiM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jKFiM.png" alt="Architecture like this" /></a></p>
  <p>The issue is when I try to insert data using EF Core methods</p>
  <blockquote>
  <p>(like adding model and then context.SaveChanges())</p>
  </blockquote>
  <p>PostgreSQL throws an error of unknown exception from PgSql.</p>
  <pre><code>{&quot;The database operation was expected to affect 1 row(s), but actually affected 0 row(s); data may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=527962 for information on understanding and handling optimistic concurrency exceptions.&quot;}
  Data: {System.Collections.ListDictionaryInternal}
  Entries: Count = 1
  HResult: -2146233088
  HelpLink: null
  InnerException: null
  Message: &quot;The database operation was expected to affect 1 row(s), but actually affected 0 row(s); data may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=527962 for information on understanding and handling optimistic concurrency exceptions.&quot;
  Source: &quot;Npgsql.EntityFrameworkCore.PostgreSQL&quot;
  StackTrace: &quot;   at Npgsql.EntityFrameworkCore.PostgreSQL.Update.Internal.NpgsqlModificationCommandBatch.Consume(RelationalDataReader reader)\r\n   at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.Execute(IRelationalConnection connection)\r\n   at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.Execute(IEnumerable`1 commandBatches, IRelationalConnection connection)\r\n   at Microsoft.EntityFrameworkCore.Storage.RelationalDatabase.SaveChanges(IList`1 entries)\r\n   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(IList`1 entriesToSave)\r\n   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(StateManager stateManager, Boolean acceptAllChangesOnSuccess)\r\n   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.&lt;&gt;c.&lt;SaveChanges&gt;b__104_0(DbContext _, ValueTuple`2 t)\r\n   at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlExecutionStrategy.Execute[TState,TResult](TState state, Func`3 
  </code></pre>
  <p>operation, Func`3 verifySucceeded)\r\n   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChanges(Boolean acceptAllChangesOnSuccess)\r\n   at Microsoft.EntityFrameworkCore.DbContext.SaveChanges(Boolean acceptAllChangesOnSuccess)\r\n   at Microsoft.EntityFrameworkCore.DbContext.SaveChanges()\r\n   at Efcore_testapp.Controllers.HomeController.Index() in C:\Users\parthraj.panchal\source\repos\Efcore testapp\Efcore testapp\Controllers\HomeController.cs:line 52&quot;
  TargetSite: {Void Consume(Microsoft.EntityFrameworkCore.Storage.RelationalDataReader)}</p>
  <blockquote>
  <p>My observation is that :-</p>
  </blockquote>
  <blockquote>
  <p>EF core has sent data to pgsql to insert in table T and is expecting confirmation from table T but as pgsql has inserted the data in partitioned table T2 it it sending confirmation from that T2 table .
  And thats where the conflict happens between pgsql and EF core.</p>
  </blockquote>
  <blockquote>
  <p>My test :</p>
  </blockquote>
  <blockquote>
  <p>As I once tested a scenario where I just disabled the triggers that were deciding where to insert data and all the flow working fine.</p>
  </blockquote>
  <p>Anyone has any idea about this ?</p>