I have a big bunch of inserts that I do through DataContext in transaction. I inserting two types of objects: A and B.
I do execute many sql inserts like:
INSERT INTO A (...) VALUES ('11111111-1111-1111-1111-111111111111',..)
INSERT INTO B (...) VALUES (
'21111111-1111-1111-1111-111111111111',
'11111111-1111-1111-1111-111111111111',...)
separately in
db.ExecuteCommand(sql.ToString(), processedParams.ToArray());
table B have foreign key to A.
Sometimes I get error like: violation of FOREIGN KEY constraint "FK_B_A" on table "A". Column "GUID".
Sometimes all records successfully inserts in to DB. Data bunch always the same except dynamically generated GUIDs.
It looks like the insert in to B sometimes occurs before inserts to A.
INSERT INTO A (column names) VALUES(actual values). A code sample from where you build your query strings might help locate this problem.