By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,677 Members | 1,890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,677 IT Pros & Developers. It's quick & easy.

Linq. Delete Record

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.