I have coded a C# MVC5 internet application, where I have a MapCompany
object that has a List<MapLocation>
. I have a DbSet<MapCompany>
as well as a DbSet<MapLocation>
. When I call the Delete Action result when trying to delete a MapCompany
object, I am getting the following error:
The DELETE statement conflicted with the REFERENCE constraint "FK_dbo.MapLocations_dbo.MapCompanies_MapCompany_Id". The conflict occurred in database "TestDatabase", table "dbo.MapLocations", column 'MapCompany_Id'.
The statement has been terminated.
Do I need to remove all the associated MapLocations
when removing a MapCompany
object? If so, what is the easiest way to do this? Is there an easier/better way rather than looping through each object, and removing each object manually? Also, at a future stage, each MapLocation
will have many MapLocationItem
objects.