Last post Aug 21, 2020 02:50 AM by Sean Fang
Aug 20, 2020 02:45 PM|amithashenoy|LINK
M having some issue with foreignkey while updating data .
I have two entities Example
So when i delete student entity and its soft delete i am not deleting from DB.And Save it. works fine.
When i save _context.SaveChanges() ,it update studenttable and sets foreignkey=null any idea why it behaves so?
Thanks in advance
Aug 21, 2020 02:50 AM|Sean Fang|LINK
I think what you mean is "Cascade Delete". A closely related concept also covered by EF Core delete behaviors is the automatic deletion of a child entity
when it's relationship to a parent has been severed--this is commonly known as "deleting orphans".
From documents, it is saying that:
There are several delete behaviors defined in the DeleteBehavior enumerator type, which can be passed to the OnDelete fluent API to control whether the deletion of a principal/parent entity or the severing of the relationship to dependent/child entities
should have a side effect on the dependent/child entities.
There are three actions EF can take when a principal/parent entity is deleted or the relationship to the child is severed:
In short, for optional relationships (the FK can be null), the default behavior is "ClientSetNull", which will set the FK property to null in memory but do nothing for database.
Hope this can help you.