Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4.5 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-31180-6
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 24th, 2013, 09:49 PM
Friend of Wrox
 
Join Date: May 2011
Posts: 411
Thanks: 13
Thanked 7 Times in 7 Posts
Default On Delete Cascade

I am reading through on page 572 of your book and I was wondering could not this be better handled if the backend of the database handled this when the database was set up with the standard triggers of on delete cascade? I have always been told that handling issues like this at the database level rather than at the front end is or has been always the best way to go.

CREATE TABLE Courses (
CourseID int NOT NULL PRIMARY KEY,
Course VARCHAR(63) NOT NULL UNIQUE,
Code CHAR(4) NOT NULL UNIQUE
);

CREATE TABLE ImarBookCourses (
EntryID int NOT NULL PRIMARY KEY,
BookID int NOT NULL,
Course CHAR(4) NOT NULL,
CourseNum CHAR(3) NOT NULL,
CourseSec CHAR(1) NOT NULL
);
and I establish a foreign key relationship between the two, like this:

ALTER TABLE ImarBookCourses
ADD FOREIGN KEY (Course)
REFERENCES Courses(Code)
ON DELETE CASCADE;

I mean I am just saying. That is all. Kind of different way to approach this matter is it not?
 
Old April 25th, 2013, 03:01 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

That really depends on the requirements. Do you really want to delete all reviews when you delete a genre? Probably not; you probably want to reassign them to another genre first.

Be aware that if you define cascade behavior at the database level, you also need to define it in the EF model to keep the two in sync. https://www.google.com/#output=searc...w=1920&bih=925

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
DB Foreign Key - Delete Rule not set to Cascade ? kalel_4444 BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio 0 August 26th, 2009 10:46 AM
SQL Server 2005 Delete on cascade DarkForce SQL Language 0 October 11th, 2008 08:24 AM
Similar Delete Cascade prasanna.nadgir C# 6 August 28th, 2007 04:12 AM
How apply cascade update/delete in sql server ? method SQL Server 2000 2 May 14th, 2005 12:02 PM
Urgent: Implement Cascade Delete through Code rcmetta BOOK: Professional Crystal Reports for VS.NET 0 June 7th, 2004 12:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.