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
So recently we had issues with a client reporting data being deleted, and we asked him for a step-by-step on what he did before the data went missing. We were a bit confused, as the step did not call for any direct Delete methods. So we went and checked our table configurations for any bugged Cascading Deletes.
However, the cascading delete looks to be correct both code-wise and in the database (We always use the build in RelationalDatabaseCreator to ensure the DB and Code is in sync). The class has a nullable property, which was a foreign key, when that property was set to NULL, it deleted the class entity from the database? This makes no sense to me.
Im not so sure whether this is a bug, or intended, in either case I would love to know why this is happening.
Create CAR entity:
Attach two Drivers to the car
So far so good..
Now, i want to remove the CAR from Driver 1 by setting CarId to NULL, this triggers a DELETE command to the database and completely removes the driver, why is this? The foreign key ive set in the DriverConfiguration should (from how i understand it) make it so IF the Car gets deleted, then the Driver is deleted as well.
Hi there,
So recently we had issues with a client reporting data being deleted, and we asked him for a step-by-step on what he did before the data went missing. We were a bit confused, as the step did not call for any direct Delete methods. So we went and checked our table configurations for any bugged Cascading Deletes.
However, the cascading delete looks to be correct both code-wise and in the database (We always use the build in RelationalDatabaseCreator to ensure the DB and Code is in sync). The class has a nullable property, which was a foreign key, when that property was set to NULL, it deleted the class entity from the database? This makes no sense to me.
Im not so sure whether this is a bug, or intended, in either case I would love to know why this is happening.
Create CAR entity:
Attach two Drivers to the car
So far so good..
Now, i want to remove the CAR from Driver 1 by setting CarId to NULL, this triggers a DELETE command to the database and completely removes the driver, why is this? The foreign key ive set in the DriverConfiguration should (from how i understand it) make it so IF the Car gets deleted, then the Driver is deleted as well.
I have attached the demo project here: test.zip
EF Core version: 6.0.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer 6.0.0
Target framework: (e.g. .NET 5.0) .net 6
Operating system: windows 10
IDE: visual studio 2022
The text was updated successfully, but these errors were encountered: