Reputation: 11
I am using EFCore.BulkExtensions for bulk insert, and I want to confirm how the library handles foreign key constraints during these operations.
Does EFCore.BulkExtensions disable foreign key checks automatically when SetOutputIdentity = false? If not, is there any scenario where the library might disable foreign key constraints implicitly during bulk operations?
In my case the FKs constraints reman disabled after some bulk inserts but it doesn't happen every time.
I am using EFCore.BulkExtensions to perform bulk inserts, and I set SetOutputIdentity = false to optimize the insert operation since I don’t need the auto-generated identity values after the insert.
Upvotes: 1
Views: 51
Reputation: 71119
No, SetOutputIdentity
is just a setting as to whether to retrieve the identity values afterwards, it does not affect the actual command.
Untrusted constraints after bulk copy is caused because you haven't set the SqlBulkCopyOptions
on the BulkConfig
. This needs to have the flag CheckConstraints
, which means the constraints will be checked on insert/update/delete, and so not marked as untrusted. You probably also want FireTriggers
.
Also, if you want to improve performance, at the cost of locking up the whole table, you can use TableLock
.
For further info, see the docs here and here.
Upvotes: 1