cascading-deletes

How to update FK to null when deleting optional related entity

徘徊边缘 提交于 2019-11-27 23:50:37
I'm reasonably new to EF, and struggling a little to facilitate deleting my objects. My two objects and associated DbContext look as follows: public class Context: DbContext { public Context() : base(){} public DbSet<Person> Persons {get;set;} public DbSet<Vehicle> Vehicles {get;set;} } public class Person { public int PersonID {get;set;} public string Name {get;set;} } public class Vehicle { public int VehicleID {get;set;} public int? PersonID {get;set;} [ForeignKey("PersonID")] public virtual Person Person {get;set;} } As per above, one person can be linked to multiple vehicles. There is no

Entity Framework: Set Delete Rule with CodeFirst

纵饮孤独 提交于 2019-11-27 20:35:25
I am using EF4 CTP 5, CodeFirst. Please see my classes first: public class Guest { [Key] public Guid GuestID { get; set; } public Language PreferredLanguage { get; set; } public Guid? LanguageID { get; set; } } public class Language { [Key] public Guid LanguageID { get; set; } [Required(ErrorMessage = "Enter language name")] [StringLength(50, ErrorMessage = "Language name is too long")] public string LanguageName { get; set; } // in origine language } My goal is to set a certain "Delete Rule" for the Guest-Language relationship. When a language is deleted, I do not want to delete the

Doctrine: cascade=“remove” vs orphanremoval=true

北战南征 提交于 2019-11-27 17:23:14
What is the difference between the 2 options above? When is it preferable to choose each option? Serge Kvashnin The basic difference between them is: When using the orphanRemoval=true option Doctrine makes the assumption that the entities are privately owned and will NOT be reused by other entities. If you neglect this assumption your entities will get deleted by Doctrine even if you assigned the orphaned entity to another one. Say your User has one-to-many relation to Comment . If you are using cascade="remove" , you can remove the reference for Comment from one User , and then attach that

What is the recommended equivalent of cascaded delete in MongoDB for N:M relationships?

旧城冷巷雨未停 提交于 2019-11-27 15:45:14
问题 Assuming the following "schema/relationship" design what is the recommended practice for handling deletion with cascade delete like operation? Relational Schema: +---------+ +--------+ | Student |-*--------1-[Enrollment]-1--------*-| Course | +---------+ +--------+ MongoDB: +---------+ +--------+ | Student |-*----------------*-| Course | +---------+ +--------+ Given this classic design of enrollment of students to courses, having a collection of courses in students and vice versa seems to be

Trigger calls in cascade deleting

ⅰ亾dé卋堺 提交于 2019-11-27 15:39:01
问题 I have table "A" in MySQL. It has some references with cascade deleting to some other tables ("B", "C", "D" ...). I need to use a trigger when something deletes from "A". This trigger works when I delete records from "A" directly. But it doesn't work with cascade deleting. Does any version of MySQL exist where my trigger will work with cascade deleting? Or, maybe, there is another way to call 回答1: From http://dev.mysql.com/doc/refman/5.6/en/innodb-restrictions.html Cascaded foreign key

Django - Cascade deletion in ManyToManyRelation

拟墨画扇 提交于 2019-11-27 15:01:29
Using the following related models (one blog entry can have multiple revisions): class BlogEntryRevision(models.Model): revisionNumber = models.IntegerField() title = models.CharField(max_length = 120) text = models.TextField() [...] class BlogEntry(models.Model): revisions = models.ManyToManyField(BlogEntryRevision) [...] How can I tell Django to delete all related BlogEntryRevision s when the corresponding BlogEntry is deleted? The default seems to be to keep objects in a many-to-many relation if an object of the "other" side is deleted. Any way to do this - preferably without overriding

MS SQL “ON DELETE CASCADE” multiple foreign keys pointing to the same table?

白昼怎懂夜的黑 提交于 2019-11-27 12:46:09
Howdy, I have a problem where i need a cascade on multiple foreign keys pointing to the same table.. [Insights] | ID | Title | | 1 | Monty Python | | 2 | Spamalot | [BroaderInsights_Insights] | broaderinsight_id | insight_id | | 1 | 2 | Basically when either record one or two in the insights table is deleted i need the relationship to also be deleted.. I've tried this: CREATE TABLE broader_insights_insights(id INT NOT NULL IDENTITY(1,1), broader_insight_id INT NOT NULL REFERENCES insights(id) ON DELETE CASCADE, insight_id INT NOT NULL REFERENCES insights(id) ON DELETE CASCADE, PRIMARY KEY(id))

How do I edit a table in order to enable CASCADE DELETE?

隐身守侯 提交于 2019-11-27 09:01:35
I have a table representing users. When a user is deleted I get: DELETE statement conflicted with the REFERENCE constraint Apparently, CASCADE DELETE is not as easy as I imagined in SQL Server, and the option needs to be added to the table. The problem is: I cannot figure out how to add the CASCADE DELETE option. I'm using: SQL Server 2008 . Any ideas how to do this? Read this Microsoft article first. Read Me . I use the GUI during design so here is a picture of how it is selected in SSMS. The syntax added to the foreign key is " ON DELETE CASCADE " Mr. TA Google ALTER TABLE DROP CONSTRAINT ,

What are the Pros and Cons of Cascading delete and updates?

廉价感情. 提交于 2019-11-27 07:44:53
问题 Maybe this is sort of a naive question...but I think that we should always have cascading deletes and updates. But I wanted to know are there problems with it and when should we should not do it? I really can't think of a case right now where you would not want to do an cascade delete but I am sure there is one...but what about updates should they be done always? So can anyone please list out the pros and cons of cascading deletes and updates ? Thanks. 回答1: Pros: When you delete a row from

How to cascade delete over many to many table

假如想象 提交于 2019-11-27 07:36:32
问题 I have a 3 tables that look like this: (source: InsomniacGeek.com) On the foreign keys I have set cascade deletes. Right now, when I delete a record in the Folder table, only the related record in the FolderItem is deleted. This is expected and correct. What I would to accomplish is when I delete a record in the Folder table, the corresponding records in the FolderItem and the Item table should be deleted. How do I solve this? By adding a trigger that deletes all instances of Item with the