I'm a bit stuck here trying to copy lots of data (a million records total) from three related tables to other three related tables in the same database.
My table design is as follows:
What I need is to be able to copy data from the draft tables over to the non-draft tables in one transaction which I'm able to roll back if anything goes wrong. This is needed because we don't want i.e. Billing
and BillingPriceLine
records to exist in the database, if the bulk insertion of BillingPriceLineSpecificationDraft
copy failed.
However, since I'm using SqlBulkCopy
for copying the records, I am not able to get a hold of the new IDs to make the correct relations between the three new tables. If I perform a read on i.e. the Billing
table in the transaction to get the correct Billing
ID, I get a time out, which is expected since the tables are locked within the transaction.
I have tried setting the IsolationLevel
enum on the transaction (in fact, I went crazy and tried them all ;-)), but they didn't do anything it seems.
Is there any good way of doing this that I'm missing?
Thanks in advance.