473,396 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Linq. Delete Record

Hello,

I have two tables:

[Tags] TagId, PostId
[PostsTags] TagId, PostId

How can I delete, given a TagId, the record from Tags and all records
associated with it in PostTags.

I have created the Linq to SQL classes.

I need to create this code inside my LinqDataSource, which I use as
DataSource of my ListView:

private void lds_Deleting(object sender, LinqDataSourceDeleteEventArgs
e)
{
}

Could someone, please, help me out?

Thanks,
Miguel

Nov 24 '07 #1
2 5455
Miguel,

Do you have a need to do this using Linq to SQL? To be quite honest, a
simple stored procedure (or even two parameterized queries) would suffice:

delete from PostsTags where TagId = ?
delete from Tags where TagId = ?

Of course, you haven't specified the relationship between the two
tables, so the above statements could be wrong.

However, I would say that using the LINQ to SQL classes in this specific
instance (where you have a very specific operation) is a little overboard.

Or, if you must use LINQ to SQL and have set up the relations between
the classes correctly, you could just call Delete on the LinqDataSource
instance.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"shapper" <md*****@gmail.comwrote in message
news:b2**********************************@g21g2000 hsh.googlegroups.com...
Hello,

I have two tables:

[Tags] TagId, PostId
[PostsTags] TagId, PostId

How can I delete, given a TagId, the record from Tags and all records
associated with it in PostTags.

I have created the Linq to SQL classes.

I need to create this code inside my LinqDataSource, which I use as
DataSource of my ListView:

private void lds_Deleting(object sender, LinqDataSourceDeleteEventArgs
e)
{
}

Could someone, please, help me out?

Thanks,
Miguel
Nov 24 '07 #2
To elaborate, in your event, you would call Delete on the associated
records. The thing is, if you have the relations set up correctly, you
^shouldn't^ have to do this.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"shapper" <md*****@gmail.comwrote in message
news:b2**********************************@g21g2000 hsh.googlegroups.com...
Hello,

I have two tables:

[Tags] TagId, PostId
[PostsTags] TagId, PostId

How can I delete, given a TagId, the record from Tags and all records
associated with it in PostTags.

I have created the Linq to SQL classes.

I need to create this code inside my LinqDataSource, which I use as
DataSource of my ListView:

private void lds_Deleting(object sender, LinqDataSourceDeleteEventArgs
e)
{
}

Could someone, please, help me out?

Thanks,
Miguel
Nov 24 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: shapper | last post by:
Hello, I have a table named Tags with the following columns: TagId and TagValue. How can I delete a record, using LINQ, given the TagId value. Thanks, Miguel
1
by: news.microsoft.com | last post by:
Hello people: First of all forgiveness for my English. I am working with Linq to SQL, Visual Studio 2008 and SQL Server 2000. When you delete a record and then go back to Insert (ie, insert a...
2
by: news.microsoft.com | last post by:
Hello people: First of all forgiveness for my English. I am working with Linq to SQL, Visual Studio 2008 and SQL Server 2000. When you delete a record and then go back to Insert (ie, insert a...
3
by: shapper | last post by:
Hello, I have 3 tables, Tags, ArticlesTags and FilesTags, with the following columns: Tags TagID, Text ArticlesTags TagID, ArticleID FilesTags TagID, FileID
2
by: Arjen | last post by:
Hi, How can I delete multiple records with Linq? On the internet I found the DeleteAll function, but this one does not exist in my library. Please help me out. Thanks!
4
by: =?Utf-8?B?RXJpYyBGYWxza2Vu?= | last post by:
We’re storing our main entity in an insert only table which stores the history of past revisions, but we’re facing problems with storing this history as LINQ will only update the entity, and...
0
by: mesut | last post by:
Hi, I'm using LINQ.. and I would like to understand if it's a bug or not in LINQ... I've a situation like: I'm reading all records via "Select" Statement and a specific select statment #1...
3
by: =?Utf-8?B?UGF1bCBQcmV3ZXR0?= | last post by:
I'm attempting to use LINQ to insert a record into a child table and I'm receiving a "Specified cast is not valid" error that has something to do w/ the keys involved. The stack trace is: ...
0
by: Big Daddy | last post by:
I am trying to do all my DB access through LINQ. For example, I am trying to delete a record from the JobQueue table. There’s a couple ways I could do this: 1. Method 1 – The disadvantage is...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.