Unique entities in a EntityCollection

Posts   
 
    
mshe
User
Posts: 167
Joined: 02-Feb-2006
# Posted on: 28-Mar-2006 00:35:09   

Hi all,

What's the best way to check if an item entered into an EntityCollection is unique?

For example:

MyEntity ID FKID (Foreign Key) Name <--- This should be unique for a FKID Value

How do I ensure that my EntityCollection of MyEntities contains unique Names for a particular FKID?

thanks simple_smile

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 28-Mar-2006 03:07:39   

Would you like this to be like a constraint on the database, or only for this particular instance of a collection? Also will this need to be done during the query and how do you know which one you would want if there were two entities? If you just want to know then you could create a hashlist with that foreign key as the key and catch the duplicate exception to indicate if it did or didn't contain that value twice.

mshe
User
Posts: 167
Joined: 02-Feb-2006
# Posted on: 29-Mar-2006 07:31:38   

bclubb wrote:

Would you like this to be like a constraint on the database, or only for this particular instance of a collection? Also will this need to be done during the query and how do you know which one you would want if there were two entities? If you just want to know then you could create a hashlist with that foreign key as the key and catch the duplicate exception to indicate if it did or didn't contain that value twice.

Hello,

I would prefer if the the "constraint" is placed in the Data Layer code rather than in the database.

I'm exposing the tables to 3rd parties as LLBLGen objects, as a result, I like to enforce certain rules (i.e. unique entities within the CampParm EntityCollection) when the items are added to the object. This way, I can throw an exception ASAP before an adapter.save is called.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 29-Mar-2006 08:17:57   

Then you might want to modify your design a little bit.

If FKID & Name are unique, then you might want to set them as the PK of the table.

And then set the EntityCollection property DoNotPerformAddIfPresent to True