Retrieve all related Entities

Posts   
 
    
gabrielk avatar
gabrielk
User
Posts: 231
Joined: 01-Feb-2005
# Posted on: 25-Jan-2006 17:28:42   

Hi,

I use the SelfServicing approach and would like to achieve the following:

I have a Contacts Table A contact in the database can linked to the following: Task Event Department Contract

Then when a user wants to delete the contact it should show all related entities so the user knows why he can't delete the user is has selected.

In the LLBL Gen / SQL Server all relations are available but without referencing integraty, because a task can also belong to a Customer and not to a Contact, so I can't enforce relations. (Sometimes a task is only assigned to a user, and no other entities).

Any suggestions would be nice!

[Extra] I know about get GetDependingEntities (I thought that was the name) but the problem is on what field to search. A task might have a creator, handler, supervisor, etc. which all are related to users. If I know Task is related to contact, how to know on which fields. Or has this to be done by hand?

Thanks. Gab

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 26-Jan-2006 06:41:29   

A brief tables structure would have cleared things out. For example the related Table Tasks, does it have let's say a field called OwnerID, which might point to a Contact. Customer or a User ?! and there is another field which determines where to point. Or it has ContactID, CustomerID & UserID, and all allow null, and it can be related to one or more of these?

Anyway in you case of relations, I think you may have to do your checking manually by querying the database before the delete.

gabrielk avatar
gabrielk
User
Posts: 231
Joined: 01-Feb-2005
# Posted on: 26-Jan-2006 09:39:03   

Tables are like:

[Task] TaskID ContactID <> Always Contact on ContactID SupervisedBy <> Always User on UserID (so if it's filled, it''s a user, but optional) HandlesBy <> Always User on UserID (so if it's filled, it''s a user, but optional) etc.

Greets, Gab

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 26-Jan-2006 10:32:01   

Do you want a generic solution (so 1 routine which checks for referential integrity for all entity types to delete) or a solution for Contact? If the latter, you can go for a small set of scalar queries (GetScalar on an entity collection) which for example retrieve the count on TaskID in Task where ContactID is the id value of the contact to delete.

Frans Bouma | Lead developer LLBLGen Pro