-
Notifications
You must be signed in to change notification settings - Fork 89
Description
We are facing an issue where the Auto Increment primary keys are not being propagated when multiple users try to submit data at the same time. We have read through another similar issue in #131, and we are already using Instance Context Mapping.
Description:
Attached code snippet is a test function we did to replicate the problem. It inserts 3 lists of orders concurrently to a_misc table using 3 different threads, simulating multiple users submitting data simultaneously. The screenshot shows the logs of MiscId returned from .Identity() after inserting a_misc, but before inserting into child table a_misc_detail. The issue is that the returned MiscId is sometimes 0 (the default int value), and because of that, inserting into a_misc_detail fails with a foreign key constraint error.
Questions:
- Is there any solution or workaround for this issue?
- May I know what is the best practice for handling concurrent insertion like this case?
ErrorMessage: Cannot add or update a child row: a foreign key constraint fails ("db.test"."a_misc_detail", CONSTRAINT "FK_a_misc_a_misc_detail_MiscId" FOREIGN KEY ("MiscId") REFERENCES "a_misc" ("MiscId"))
- Dapper version: 2.0.123
- Dapper Plus version: 7.3.0
- Database Provider: MySql 8.0.30