473,498 Members | 1,633 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Delete Record using Linq

Hello,

I have 3 tables, Tags, ArticlesTags and FilesTags, with the following
columns:

Tags TagID, Text

ArticlesTags TagID, ArticleID

FilesTags TagID, FileID

I need to delete all records in Tags which are not in ArticlesTags and
FilesTags.

If a Tag is present in one of the 2 tables, ArticlesTags or FilesTags,
then it will not be deleted.

How would I do this?

Thanks,

Miguel
Mar 7 '08 #1
3 2164
Just a thought - in this scenario, you aren't really interested in the
fields of the things you are deleting, so I wouldn't bother feftching
them from the database (which will be necessary [or at the least, all
the PKs of such] if you want LINQ to delete them).

If this was me, I'd write a stored procedure that used a few NOT
EXISTS checks, and drag the SP into LINQ (juts to simplify the calling
mechanism).

LINQ is a great tool, but you can mix-and-match generated code and SPs
so that each does things it is good at.

Marc
Mar 7 '08 #2
On Mar 7, 4:56 am, Marc Gravell <marc.grav...@gmail.comwrote:
Just a thought - in this scenario, you aren't really interested in the
fields of the things you are deleting, so I wouldn't bother feftching
them from the database (which will be necessary [or at the least, all
the PKs of such] if you want LINQ to delete them).

If this was me, I'd write a stored procedure that used a few NOT
EXISTS checks, and drag the SP into LINQ (juts to simplify the calling
mechanism).

LINQ is a great tool, but you can mix-and-match generated code and SPs
so that each does things it is good at.

Marc
Hi,

I know ... but in this moment I would like to use only Linq for
this ...
.... later I will probably use a SP.

I came up with:

Dim database As New CodeDataContext
Dim tags = From t In database.Tags _
Where Not (t.FilesTags.Any Or t.ArticlesTags.Any) _
Select t
database.Tags.DeleteAllOnSubmit(tags)
database.SubmitChanges()

It is working. Just one question:
What do you mean with getting only the ID?
How do I do that in my code?

Thanks,
Miguel

P.S: Sorry for my VB.NET code but I am more used to is and it is
faster for me.
When will converters work also with Linq code?
Mar 7 '08 #3
What do you mean with getting only the ID?
How do I do that in my code?
I don't know if it is possible; but it would be theoretical bare-minimum to
perform a delete...

But I stress; if it was me, I wouldn't be getting the data out of the
database...

Marc
Mar 7 '08 #4

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

Similar topics

2
5459
by: shapper | last post by:
Hello, I have two tables: TagId, PostId TagId, PostId How can I delete, given a TagId, the record from Tags and all records associated with it in PostTags.
3
24211
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
2
1460
by: shapper | last post by:
Hello, I have a ListView defined as follows: Private Sub lv_Init(ByVal sender As Object, ByVal e As EventArgs) Handles lv.Init lv.DataKeyNames = New String() {"TagID"} lv.ID = "lv"...
3
1916
by: plonk | last post by:
Hi I'm trying to learn sql by getting a database up and running on VB.net 2008 and SQL server express. I have the database connected correctly, (i think) but when i try to add a record using this...
1
4959
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
1662
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
8110
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!
0
2337
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...
0
3676
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
7004
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
7208
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...
1
6890
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
7379
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...
1
4915
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4593
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3095
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
657
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
292
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.