Many to many duplicate entries best practice

Posts   
 
    
Maxus
User
Posts: 76
Joined: 04-Aug-2006
# Posted on: 20-Jul-2007 10:37:53   

Hi People,

Another very simple question, I am just wondering what the best practise for check if a relation is already defined for a given many to many.

For instance if I have

A -> B <-C

whats the best way of checking before adding a record that an entry tieing table a and C together doesn't already exist?

Thanks Alex

PS I am using the adapter pattern.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 20-Jul-2007 10:49:49   

For instance if I have

A -> B <-C

whats the best way of checking before adding a record that an entry tieing table a and C together doesn't already exist?

Either try to fetch it from B before adding it. Or use a Unique Key constraint on B (AId & cId), and try to save the new B entity and handle the unique constraint violation exception if found.

Maxus
User
Posts: 76
Joined: 04-Aug-2006
# Posted on: 20-Jul-2007 10:55:09   

Thanks for the fast reply, I might go with fetching it first but I will also add a unique constrait. Just wondered if LLBLgen had a trick up its sleeve as it does for almost everything simple_smile

Thanks! Alex