Delete in M:N relationships

Posts   
 
   
 
Anonymous
User
Posts: 0
Joined: 11-Nov-2006
# Posted on: 05-Jun-2007 15:20:55   

llblgen 2.0.0.0 Final. Adapter templates.

I have tables as follows:

Product (m:n) Category <becomes> Product (1:m) ProductVsCategory (n:1) Category

For a specific ProductEntity I need to remove all of the relationships from the ProductVsCategory table. What's the best way to handle this?

Cheers

jbb avatar
jbb
User
Posts: 267
Joined: 29-Nov-2005
# Posted on: 05-Jun-2007 15:57:46   

Hello,

you can use the DeleteEntitiesDirectly method to delete all your ProductVsCategory for example:


dim rpb as new RelationPredicateBucket((ProductVsCategory.IdProduct == "1"));
adapter.DeleteEntitiesDirectly("ProductVsCategoryEntity",rpb)


Anonymous
User
Posts: 0
Joined: 11-Nov-2006
# Posted on: 05-Jun-2007 16:46:24   

Hi jbb,

I hae something very similar:


IRelationPredicateBucket bucket = new RelationPredicateBucket(EventProductFields.ProductId == entity.ProductId);
work.AddDeleteEntitiesDirectlyCall("ProductVsCategoryEntity", bucket); 

However when I attempt to run this I recieve the following error:


An exception was caught during the execution of an action query: The multi-part identifier "Online Store.dbo.EventProduct.ProductId" could not be bound.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.

EventProduct Inherits from Product. Product has the m:n relationship with Category.

Any ideas? :S

Cheers

jbb avatar
jbb
User
Posts: 267
Joined: 29-Nov-2005
# Posted on: 05-Jun-2007 16:49:59   

Hello,

You have to add the relation between EventProduct and ProductVsCategory entity in the bucket or apply the bucket directly to ProductVsCategory as I said higher.

Anonymous
User
Posts: 0
Joined: 11-Nov-2006
# Posted on: 05-Jun-2007 17:15:31   

Works great. Lord only know what I was thinking before simple_smile

Cheers