Questions tagged [cascading-deletes]

The concept of SQL databases deleting rows that refer (via a foreign key) to a deleted row.

The concept of SQL databases deleting rows that refer (via a foreign key) to a deleted row. The deletion is performed recursively and enabled with the ON DELETE CASCADE property of the foreign key.

587 questions
2
votes
3 answers

How to properly enable EF cascade delete with conventions

I'm using EF 6.4.0 codefirst on a winforms app and Cascade delete is not working below are my CLASSES public class PLAYERS_M { [Key,DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int PM_ROWID { get; set; } public string…
Asım Gündüz
  • 1,257
  • 3
  • 17
  • 42
2
votes
4 answers

SQL 'DELETE CASCADE'

I have a table B that has a foreign key to table A, and now I want to do a sorta "DELETE CASCADE" thingie on A, but PostgreSQL won't accept the following: DELETE FROM ATable WHERE aid IN ( DELETE FROM BTable WHERE aid IN ( ...…
Jonas Byström
  • 25,316
  • 23
  • 100
  • 147
2
votes
2 answers

MSSQL: how to have multiple cascades with referencing the same table

Maybe a complicated situation but this is a simplified version of my model: Situation: drop table table4 drop table table2 drop table table3 drop table table1 drop table table0 create table table0 ( id integer not null primary key ) create…
Michel
  • 9,220
  • 13
  • 44
  • 59
2
votes
2 answers

Bidirectional one to many (or many to one) cascade delete behaviour. It works, but why?

I have two Nhibernate mappings for two classes, Category and Product. My Category class has two properties that are collections. The Children property is a collection of type Category which represents child categories (represents a category menu,…
dezzy
  • 479
  • 6
  • 18
2
votes
2 answers

Delete object and all its child objects in Entity Framework?

I've been trying to find the answer to this question here. Several people seem to ask similar things, but I don't get the answers. I have an EF entity with a bunch of child entities (one-to-many relationship). I want to be able to delete the…
Anders
  • 12,556
  • 24
  • 104
  • 151
2
votes
1 answer

Not able to Delete a record from Parent table having child records even after having Cascade All enabled

I have a table Department with one to many mapping to Employee table and having cascade type as all. @OneToMany(mappedBy="department",orphanRemoval = true, cascade = CascadeType.ALL, fetch = FetchType.LAZY) @Fetch(FetchMode.JOIN) private…
2
votes
1 answer

Using EF4 CTP5 code first with no cascade delete

I'm using code first and turned off the cascade delete for all foreigns keys using the following statement: protected override void OnModelCreating(ModelBuilder modelBuilder) { …
Gregoire
  • 24,219
  • 6
  • 46
  • 73
2
votes
1 answer

JOOQ CASCADE Delete

Cascade deletion is not allowed at the database level and should be implemented in the application layer. Trying to implement using JOOQ. At present my thoughts are as follows Given: a parent record that extends UpdatableRecord Get the list of…
fh76
  • 283
  • 2
  • 5
  • 14
2
votes
1 answer

EF Core - code first - multiple cascade paths

I know a lot has been written about that subject, so let me say first I carefully read first 2 pages on Google about this topic. Many suggest to put DeleteBehavior.Restrict, and dotnet ef database update does not complain anymore. Problem solved…
2
votes
1 answer

SQL Server Foreign Key "On Delete Set Null " constraint not working

I am using sql server express 2008 with mmse. i have set up a foreign key constraint between to tables and set the on delete constraint to "set null". however it does no seem to enforce the constraint and i am left with the ID in the field of the…
2
votes
1 answer

How can I specify null to foreign keys on parent delete at once in M-V-C Code first approach?

I have many tables which have foreign key relations. Such as Countries and Cities relationship. When I am deleting the country my application is breaking down because I have foreign key relationship. What I want is if user deletes the country, it…
John Adam
  • 220
  • 2
  • 14
2
votes
1 answer

Core data delete all relationship entity

Let say I have core data and three entity inside : Department, Employee, Inventory So every department could have more employees, and every employee could have more items that is record as inventory. Department <--->> Employee <---->> Inventory Now…
Marko Zadravec
  • 8,298
  • 10
  • 55
  • 97
2
votes
1 answer

NHibernate: c# action on cascade deletion

I've implemented one-to-many code mapping with cascade deletion. I have associated file with child entity. I want to delete file automatically on child cascade deletion. How can it be implemented?
Dem0n13
  • 766
  • 1
  • 13
  • 37
2
votes
1 answer

Django models - how to cancel on_delete=models.CASCADE

Trying to migrate a field from cascade to "non-cascade" seems to be ignored (Django 1.10). Previous model: class Run(models.Model): ... analysis_retention = models.ForeignKey('analysis_retention.AnalysisRetention', …
user3139774
  • 1,295
  • 3
  • 13
  • 24
2
votes
4 answers

Entity Framework: how to delete related entity upon update or delete of 'generic' parent

I have a Product class, which contains a Picture property. Other classes may also have a picture, e.g. a Customer can have a Picture. Product.cs: public class Product { public Picture Picture { get; set; } } Customer.cs: public class…
fikkatra
  • 5,605
  • 4
  • 40
  • 66