Closed geremysremitter closed 1 year ago
Hello @geremysremitter ,
We are probably missing a piece of the puzzle, but so far, everything seems to work: https://dotnetfiddle.net/bUQjIb
Could you edit this fiddle or provide a project that reproduces this issue?
Best Regards,
Jon
Hi and thanks for the super fast response. We have some real wizardry going on here as I am able to make the Fiddle work in a simple console project (thanks for that) but as soon as I port it to our big project (line for line) I continue to get the foreign key complaint. It's a mystery at present and still digging.
Thanks and I can update here if anything comes of the investigation that might be worth noting.
This is resolved by starting with the working .Net fiddle then bringing into a console app and verifying the schemas references by the entity attributes. One thing we found was that the entity name should match the table name as we had tweeked these due to the various attempts and replicating some tables in different schemas so the whole mess of evaluating seemed to be the issue. Otherwise this is a beautiful library and looking forward to working with the merge features. Thanks again for the quick response !
Awesome, I'm happy that you solved your issue.
Thank you as well for your good word, always feel great to hear those ;)
Have a good day,
Best Regards,
Jon
Description
Following your examples for one-to-one and one-to-many bulk inserts, we are unable to get beyond first bulkinsert. It appears that that the entity model should be receiving the new ids created during insert but after watering down the logic (for diagnostics) we are not seeing the actual SQL identity values manifesting in the C# entity model and believe this is the reason we get one bulkinsert to work (which is beautiful) but not the child tables -
Exception
Microsoft.Data.SqlClient.SqlException: 'The INSERT statement conflicted with the FOREIGN KEY constraint "FK_AccountContact_Contact". The conflict occurred in database "{db}", table "Core.Contact", column 'ContactId'. The statement has been terminated.'
Fiddle or Project (Optional)
Code looks like this
Additionally, SQL table defs look like the following
Further technical details