Hi,
I got "The DELETE statement conflicted with the REFERENCE constraint...." error when using Unit of Work Delete(TPrimaryKey id) function for my parent child data/table. The id that I passed in into the delete function is the parent id.
I understand that this is due to I tried to delete the parent without deleting the children. What is the correct way to do this?
I had also tried to use Delete(TEntity entity) and supply the entity with the parent object (children included), but still no luck.
var parentObj= _parentRepository.Get(parentId);
_parentRepository.Delete(parentObj);
2 Answer(s)
-
0
Hi,
This is not a unique problem to ABP. If you don't use ABP and use plain EntityFramework, same will happen. So, what's the solution? There are some alternatives:
- You can define cascade delete in db level.
- You can delete children first.
- You can make the parent ISoftDelete.
All has advantages and disadvantages. There maybe other alternatives, these are what I'm making for such cases based on the case.
-
0
<cite>hikalkan: </cite> Hi,
This is not a unique problem to ABP. If you don't use ABP and use plain EntityFramework, same will happen. So, what's the solution? There are some alternatives:
- You can define cascade delete in db level.
- You can delete children first.
- You can make the parent ISoftDelete.
All has advantages and disadvantages. There maybe other alternatives, these are what I'm making for such cases based on the case.
Hi Hikalkan,
Thanks for your reply. Yeah i guess i will try to sort it out from EF level.
Thank You.