Delete collection with where statement on related entity

Posts   
 
    
G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 24-Aug-2007 15:37:35   

Hi,

I have a project.

A project has metadata via a n:m relation.

I have a inbetween table called ProjectMetadata. In this table I have two columns: ProjectID and MetadataID.

Metadata has a CategoryID.

I wish to delete all rows from ProjectMetadata connected to a project with a specific CategoryID. I don't need to retrieve the data, just delete them ...

So the SQL Statement will be:


DELETE FROM ProjectMetadata
WHERE    (ProjectID = 21) 
   AND (MetadataID IN
      (SELECT MetadataID FROM Metadata WHERE CategoryID = 14))

Can anyone tell me how to do this?

Thanks in advance,

G.I.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 24-Aug-2007 16:03:44   

For SelfServicing, use DeleteMulti(). For Adapter, use adpater.DeleteEntitiesDirectly()

And in any case, you should pass a predicate expression with 2 predicates / filters added. The 1st predicate should be (ProjectMetadataFields.ProjectID == 21) For the second predicate you should use a FieldCompareSetPredicate.

G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 05-Sep-2007 23:26:20   

As a reply so you know it's fixed. Thank you for the needed push into the right direction!sunglasses