You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not really sure if this is a bug or just a change in the EF that caused some issues in our app. Hoping someone may be able to shed some light on it.
I have a method that creates or updates a database record that started throwing an exception when I updated the app from EF 5 to EF 8. Here's the scenario:
A DTO is passed in via an API and used to update a database record. I'm using the SetValues method to update the properties on the entity with the properties on the DTO. Everything works as it should unless I also loop through and add child objects to the entity.
If I assign things manually without using SetValues, EF adds the parent to the database, returns the parent Id, updates the child navigation property and saves the child to the database. Just like it should.
However, if I update the parent using the SetValues method, EF does not return the parent Id and assign it to the navigation property of the child. Instead it throws a foreign key violation exception.
This issue is lacking enough information for us to be able to fully understand what is happening. Please attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate.
I've uploaded a small project that shows what I am experiencing. I tested this with EF Core versions 2 through 6 and it works as expected. The change appears with version 7, which is where the uploaded project is. It also throws an exception with version 8.
Bug description
I'm not really sure if this is a bug or just a change in the EF that caused some issues in our app. Hoping someone may be able to shed some light on it.
I have a method that creates or updates a database record that started throwing an exception when I updated the app from EF 5 to EF 8. Here's the scenario:
A DTO is passed in via an API and used to update a database record. I'm using the SetValues method to update the properties on the entity with the properties on the DTO. Everything works as it should unless I also loop through and add child objects to the entity.
If I assign things manually without using SetValues, EF adds the parent to the database, returns the parent Id, updates the child navigation property and saves the child to the database. Just like it should.
However, if I update the parent using the SetValues method, EF does not return the parent Id and assign it to the navigation property of the child. Instead it throws a foreign key violation exception.
Your code
Stack traces
Verbose output
EF Core version
8.0.13
Database provider
No response
Target framework
.NET 8
Operating system
No response
IDE
No response
The text was updated successfully, but these errors were encountered: