BulkInsertupdate fails in EF Core

204 views Asked by At

Multi Level child upsert fails with an exception

Microsoft.Data.SqlClient.SqlException (0x80131904): The MERGE statement conflicted with the FOREIGN KEY constraint

when using EF Core bulk extension plugin.

When I try to update an entity, new child entities are not inserted.

2

There are 2 answers

0
Denis Kiryanov On

Hope this comment contains a solution to this issue, please take a look: stackoverflow.com/questions/50130678/

0
Majid Shahabfar On

This is likely because the value of the foreign key column in the row being inserted or updated does not match any value in the primary key column of the related table. So, please take a look at the values of related tables. But instead of using EF Core bulk extension plugin, I recommend you upgrade your code to .NET 7.0 and take advantage of the new bulk update and delete capability in EF Core 7.0.