Alessandro Del Sole's Blog

/* A programming space about Microsoft® .NET® */
posts - 159, comments - 0, trackbacks - 0

My Links

News

Your host

This is me! This space is about Microsoft® .NET® and Microsoft® Visual Basic development. Enjoy! :-)

These postings are provided 'AS IS' for entertainment purposes only with absolutely no warranty expressed or implied and confer no rights.

Microsoft MVP

My MVP Profile

I'm a VB!

Watch my interview in Seattle

My new book on VB 2015!

Pre-order VB 2015 Unleashed Pre-order my new book "Visual Basic 2015 Unleashed". Click for more info!

My new book on LightSwitch!

Visual Studio LightSwitch Unleashed My book "Visual Studio LightSwitch Unleashed" is available. Click the cover!

Your visits

Follow me on Twitter!

CodePlex download Download my open-source projects from CodePlex!

Article Categories

Archives

Post Categories

.NET Framework

Blogroll

Help Authoring

Microsoft & MSDN

Setup & Deployment

Visual Basic 2005/2008/2010

ADO.NET Data Services: deleting entities with associations

Probably this topic is more generally related to the ADO.NET Entity Framework programming, but in my case this was an issue I was experiencing with the ADO.NET Data Services, exposing an entity data model (I recorded some videos about).

Imagine you have a client application that sends a DELETE Http requests to a Data Service for deleting entities on the database. It's not unusual that your entity will have associations with other entities and so on. The "delete" action gets performed on the Entity Data Model, because this is just a .NET representation of the data source, but you'll probably get errors when trying to invoke the DataService.SaveChanges method, because the engine will try to delete a record from the database, which has associations. So, it would be necessary also to remove associated records. A work-around to accomplish this is setting the Delete action from within SQL Server Management Studio for a particular foreign key.

Supposing we're working on the Northwind database and our goal is being able of removing Orders with Order_Details associated, we can open the database and navigate to the foreign key called FK_Order_Details_Orders under the Order_Details table, as shown in the following picture:

Click the Modify command, and you'll be able to see the Foreign Key Relationships window. Here you can change the Delete rule to Cascade, as shown in the following picture:

In this way, deleting and Order entity will allow removing associated Order_Details. Another best practice in deleting entities is enforcing FK associations and regarding this Beth Massi wrote a great blog post which you can find here.

Alessandro

Print | posted on sabato 11 aprile 2009 14:04 | Filed Under [ Visual Basic Windows Communication Foundation ]

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 1 and 2 and type the answer here:

Powered by:
Powered By Subtext Powered By ASP.NET