Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

Delete Record using Linq

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
shapper - 07 Mar 2008 01:32 GMT
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
Marc Gravell - 07 Mar 2008 04:56 GMT
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
shapper - 07 Mar 2008 15:19 GMT
> 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
[quoted text clipped - 9 lines]
>
> 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?
Marc Gravell - 07 Mar 2008 15:45 GMT
> 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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.