LINQ: How to delete automatically on delete from association table


I'll try to explain my problem with an example:

 In DB(ms swl server 2005) I've 2 tables:

A(ID, SomeAText)

B(AID, SomeBText)


In LINQ TO SQL (in mdbd file) I've association:

A.ID --- Association ---> B.AID

In Table B we can have many rows is same AID value

Also, I've GridView which represents all rows from A table with LinqDataSource.

Is there way how to set in LINQ that when delete a row from A table,
AUTOMATICALLY all rows from B with AID(which points to ID of the deleting row from A) to be
deleted too ?


Thanks in advance!
Global Polls
7/16/2008 6:49:51 AM 29906 articles. 0 followers. Follow

1 Replies

Similar Articles

[PageSpeed] 20

It would be significantly better practice to create the foreign key in SQL Server and tell it to cascade the delete down. This is the sort of feature that belongs entirely in the database.

7/16/2008 11:29:11 AM

Similar Artilces:

Delete from 2 tables in one delete statement in SQL 2005
Hi,i want to delete rows from two tables using one sql statement (inner join).One table is tblEmployee and other is tblUser and i want to delete all record in both of table whose UserID is EE00001 Create a foreign key on the database table for that field, and set the cascade option to delete. When you delete from the main table, the corresponding entry from the dependent table will also be deleted.Please Mark As Answer posts that helped you."If we learn from our mistakes, I should be brilliant by now."MCTS - .NET Framework 2.0: Web Applications I agree with the previous p...

Deletes are not being deleted.
Using ASA 7.03 I am having a problem in deleting field service orders that have been completed. Just getting started with sync so I am probably making a dumb mistake or just leaving out a step. The download_delete_cursor script is: Select ordernumber from ServiceOrderEntryMaster where Tech = ? and Order_Complete = 'Y' This based on the verbose reply from the MobiLink Synchronization server is picking the correct work order ( number 326 ) and showing a Delete Row line in the log. But the work order is not being deleted on the remote side. What could I be doing wron...

Deleting the master table withour deleting the child tables
Hi i have to delete the master table data without deleting the child table records,is there any solution for this,  parent table has relation with the child table. regards vinod.t.vSoftware EngineerUshustechTechnoparkTrivandrum India You need to temporarily disable constraints on the table. Disable constraints: ALTER TABLE MyTable NOCHECK CONSTRAINT ALL Enable constraints: ALTER TABLE MyTable CHECK CONSTRAINT ALL    If this post was useful to you, please mark it as answer. Thank you! Thanks johram i can try this solution, this is usefullSoftware Enginee...

Delete row and delete from table
Hi I need, after delete a grid row, execute a delete statmentProtected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand Dim advogado As StringIf (e.CommandName = "Apagar") Thenadvogado = RTrim(e.CommandArgument.ToString)Apaga_Processos(advogado)End Ifend subPrivate Sub Apaga_Processos(ByVal advogado As String)Dim conn As SqlConnectionDim comm As SqlCommandDim connectionString As String = ConfigurationManager.ConnectionStrings("").ConnectionStringconn = New Sql...

I use SQL 2000, can you use one Delete query to delete 2 tables?
this is my Delete Query NO 1 alter table ZT_Master disable trigger All Delete ZT_Master WHERE TDateTime> = DATEADD(month,DATEDIFF(month,0,getdate())-(select Keepmonths from ZT_KeepMonths where id =1),0) AND TDateTime< DATEADD(month,DATEDIFF(month,0,getdate()),0) alter table ZT_Master enable trigger All   I have troble in Delete Query No 2 here is a select statemnt , I need to delete them select d.* from ZT_Master m, ZT_Detail d where (m.Prikey=d.MasterKey)  And m.TDateTime> = DATEADD(month,DATEDIFF(month,0,getdate())-(select Keepmonths from ZT_KeepMonths wher...

Entitlements and Associations Deleted on Deleting the Driver
Is it a known fact that on deleting a driver, its related associations and entitlements are automatically removed as well from all the users? We are noticing this behavior and wanted to confirm. I know that driver associations gets deleted from all users but not sure about Entitlements. Strangely even the entitlements (provisioned by that driver) are getting automatically deleted as well upon deletion of the driver. Is there any way in which I can avoid this? Any pointers would be appreciated.. Thanks -- saurabhbl ----------------------------------------------------...

Deleting a sql table..?
Hey all,I had created a table that contains a foreign key (to Community_ContentPages).  I would like to delete/drop the table, but I'm unsure of what consequences that might have on the GCN.  Is there a "good" way of dropping a table?  Or can I just delete the table??  Thanks!JPPS. Am using VS.NET 2003 and Enterprise Manager Foreign Key is DRI(declarative referential integrity) related you have to drop the key before you drop the table so you don't do inserts that goes to a table you have dropped.  There are two ways to drop the key with the Gui right click on...

delete tables automatically
How can I delete tables in a SQLServer Database automatically (at the moment I just do it using Micorosft SQl Management Studio Express manually) But its important that I can do that automatically, the best thing would be if I can do that from a .NET programm.  thanks in advance,mulata  Does Automatically means just sending a query from you program? DELETE FROM TABLENAMECheersAlMy BlogMapStats.NETPlease click on 'Mark as Answer' if this post answered your question! yes, but how can I implement that in my .NET program?The Database should simply be cleared total...

Problem with Entity Model after deleteing table: cannot delete in Store, there can't add same table again
Moved by moderator XIII: This question's more related to the designer of Visual Studio 2008. Questions about Entity Framework itself should be posted into the Data Access forum:  Hi,  I am having a problem creating an Entity Data Model using Visual Studio 2008. To reproduce... Create a new data model. Added some tables by selecting Update Model from Database. Look in the Model Browser, tables are added under Entity Types. Delete one of the tables, the table is gone from Entity Types but is still in the Model Store under Tables/Views Now, when I select Update Mo...

accidentally deleted a table in my local SQL Server how can I get back the table
Hi, I accidentally deleted a table in my local server. How can I get back the table? I did not do it as a transaction! Thanks in Advance You need to restore back from your backup if available. There may be third party softwares that allow you to do such operations ... HTH, Vinod Kumar MCSE, DBA, MCAD, MCSD

Function for Linq to SQL delete
Hi Guys I am new to Linq .I am wondering how can i use a function for deleting all rows fro a table in SQl server 2005 database usingLinq Query.I am usingVS 2008 (in ) and SQL server 2005 Please let me know if u have any idea ..It is very urgent Hi anupamabr, You have to select all the records of the table first and then call a delete function on them. Please try this... Dim dc As New DataClassesDataContext()Dim Query = From obj In dc.TableName _                   Select objdc.TableName....

PTR delete == A delete
Hi, i want to delete PTR record but not de A record. if i delete the PTR the A-record is also deleted. (use iManger & DNS console) is there a way to only delete PTR-record's? Niels van de Haar Systeembeheer In article <QwvDd.17151$>, wrote: > if i delete the PTR the A-record is also deleted. (use iManger & DNS > console) > What version of NAMED? NetWare? Service Pack? bd NSC Volunteer SysOp Netware 6.5 Sp2 (named from that netware sp) >>> Brad Doster<> 7-1-2005 17:1...

Delete Confirm not Deleting
I followed the instruction in this tutorial ( to add delete confirm to a GridView's FieldCommand Delete button.  It will delete the record if I comment out this code but not if I don't.  I get the confirm dialog and a postback but the record is not deleted.  DataKeyNames are set.  What's the deal?Here's the code.Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs)         'Delete Confirm     &nbs...

Linq to SQL deleting columns
We are using LINQ to develop an in house application and I am having some issues with it.  My first issue - I have a query that returns multiple possible rows.  For example there is 4 columns with one being program_id.  If I select all rows where program_id = 1, I receive 4 rows with all 4 columns.  The problem is the fourth column has all the same values, so the users do not want to see that column.  I tried to handle all this in the stored procedure, but LINQ see the multiple select statements within a case statement and always returns all columns.My question is th...

Web resources about - LINQ: How to delete automatically on delete from association table -

Piccolo Automatically Sends Users Prints Of Their Photos On Facebook, Instagram
... a popular day for debuting Instagram applications and services, as startup Piccolo announced its beta launch, aimed at allowing users to automatically ...

Facebook Status Update Tagging Now Automatically Suggests Matches for People, Pages and Other Content ...
Facebook has just changed its status update tagging tool to automatically display a drop-down menu of friends, Pages, events and groups you might ...

Meekan - schedule meetings and events automatically on the App Store on iTunes
Get Meekan - schedule meetings and events automatically on the App Store. See screenshots and ratings, and read customer reviews.

Does Google see automatically generated content as a bad thing? - YouTube
Does Google see automatically generated content as a bad thing (i.e. spam)? If I publish uncopyrighted content on my site that is available from ...

Emailing porn at work not automatically sackable, court finds
The federal court has upheld a ruling that found emailing pornography in the workplace is not automatically a sackable offence.

Emailing porn at work not automatically sackable, court finds
Australia's federal court has upheld a ruling that emailing pornography in the workplace is not automatically a sackable offence.

Shazam iPhone app now listens for music, TV shows automatically
Shazam has updated its iPhone app to tag songs, TV shows and more on its own, no longer requiring users to open the app and tap a button.

App of the day: Human for iPhone automatically tracks your movements
Human for the iPhone is an activity tracker that automatically distinguishes between different types of movement.

iPhone 5 automatically rotates using Cycloramic App. - YouTube
[NEW VIDEO] Cycloramic 2.0 update teaser vid with panoramic photo preview: Cycloramic has been Awarded ...

Resources last updated: 12/11/2015 7:00:00 PM