linq2db / linq2db.EntityFrameworkCore

Bring power of Linq To DB to Entity Framework Core projects
MIT License
446 stars 39 forks source link

PK of Entity not set after bulk copy #392

Open boomgetchopped opened 1 week ago

boomgetchopped commented 1 week ago

Hello, is there a way for bulkcopy to set the PKs of the records inserted? I need to use the PK values in subsequent save operations after the bulkcopy. Thanks.

Using MS Sql Server

MaceWindu commented 1 week ago

Bulk copy doesn't provide such functionality so some of your options are:

  1. set ids on client before instert (and allow identity insert if identity pk used)
  2. load records after bulk copy
  3. insert using MergeWithOutput to return generated ids and then assign them manualy
  4. for ids, generated by sequence: use DataExtensions.RetrieveIdentity to assign ids to entities using database sequence and then insert them using bulk copy