cascading-deletes

How to use delete cascade on MySQL MyISAM storage engine?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 06:50:59
问题 I have one table that I had called equipment , and 8 other tables that I had called equipment_child1 and so on until equipment_child8 . The commom field between all that tables is cod_equip , with this field I 'm able to identify all my child equipment tables with equipment parent table. I need to delete data from equipment when the equipment is moved, but I need to delete data in all my tables equipment_child1 to equipment_child8. then I remenber I had used DELETE CASCADE in innoDB engine,

Entity Framework on delete cascade

允我心安 提交于 2019-11-27 03:16:53
问题 I have problem with deleting related rows in Entity Framework 4.1. I have tables with relations Book 1<--->* BookFormats I have set the on delete cascade: ALTER TABLE [dbo].[BookFormats] WITH CHECK ADD CONSTRAINT [FK_BookFormats_Book] FOREIGN KEY([BookID]) REFERENCES [dbo].[Book] ([BookID]) on delete cascade The EDMX property Then, I want to remove the all BokFormats items related to my Book object: var originalBook = m.db.Book.First(x => x.BookID == bookId); originalBook.BookFormats.Clear();

SQLite Delete Cascade not working

廉价感情. 提交于 2019-11-27 01:14:54
问题 In Android 4.2, using SQLite 3.7.11, when I delete a row from the Quizzes table, who's schema is below, the corresponding rows in the QuizQuestions table are not deleted. I can't figure out what's wrong. I have tried putting db.execSQL("PRAGMA foreign_keys = ON;"); before and after the create table statements. Create table statements: CREATE TABLE quizzes(quiz_name TEXT PRIMARY KEY COLLATE NOCASE); CREATE TABLE quizQuestions(quiz_name TEXT, question_id INTEGER, PRIMARY KEY(quiz_name, question

JPA/Hibernate remove entity sometimes not working

拟墨画扇 提交于 2019-11-26 21:54:32
I have the following code that usually works well: public void delete(T object) { EntityManager em = getPersistence().createEntityManager(); EntityTransaction et = em.getTransaction(); try { et.begin(); object = em.find(object.getClass(), object.getId()); em.remove(object); em.flush(); et.commit(); } catch(Exception e) { error("Unable to delete " + object.toString() + ": there are references to it."); } finally { if (et.isActive()) et.rollback(); em.close(); } } For many of my entity classes this just works. However for two of them it does nothing, it does not throw any exceptions and it does

Cascade delete using Fluent API

好久不见. 提交于 2019-11-26 21:42:28
问题 I have two entities. Profile and ProfileImages . After fetching a Profile I want to delete ProfileImages through Profile without it just removing the reference to Profile (setting it to null ). How can this be done with fluent API and Cascading Delete? Do I set the HasRequired attribute or the CascadeDelete attribute? public class Profile { //other code here for entity public virtual ICollection<ProfileImage> ProfileImages { get; set; } } public class ProfileImage { // other code here left

How to add “on delete cascade” constraints?

柔情痞子 提交于 2019-11-26 21:40:21
In PostgreSQL 8 is it possible to add ON DELETE CASCADES to the both foreign keys in the following table without dropping the latter? # \d scores Table "public.scores" Column | Type | Modifiers ---------+-----------------------+----------- id | character varying(32) | gid | integer | money | integer | not null quit | boolean | last_ip | inet | Foreign-key constraints: "scores_gid_fkey" FOREIGN KEY (gid) REFERENCES games(gid) "scores_id_fkey" FOREIGN KEY (id) REFERENCES users(id) Both referenced tables are below - here: # \d games Table "public.games" Column | Type | Modifiers ----------+------

How to update FK to null when deleting optional related entity

淺唱寂寞╮ 提交于 2019-11-26 21:34:34
问题 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

Cascading deletes with Entity Framework - Related entities deleted by EF

断了今生、忘了曾经 提交于 2019-11-26 20:24:29
I have an issue with deletion in Entity Framework. In short, EF explicitly tries to delete an entity from the database even though I've explcitly configured EF to use cascading deletes in the database. My design: I have three entity types, MainEntity , EntityTypeA and EntityTypeB . EF has been configured to use cascade deletion when deleting EntityTypeA and EntityTypeB . In other words, if I delete an instance of MainEntity , I want all related EntityTypeA and EntityTypeB instances to be deleted as well. I never delete EntityTypeA or EntityTypeB without also deleting their parent. My problem

Entity Framework: Set Delete Rule with CodeFirst

拈花ヽ惹草 提交于 2019-11-26 20:24:05
问题 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"

Doctrine: cascade=“remove” vs orphanremoval=true

半腔热情 提交于 2019-11-26 18:56:42
问题 What is the difference between the 2 options above? When is it preferable to choose each option? 回答1: 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