Maintain referencial Integrity for Delete

Posts   
 
    
Rajini
User
Posts: 2
Joined: 24-Sep-2008
# Posted on: 24-Sep-2008 13:10:54   

Hi Friends,

This might be a basic question.but I am struggling on this and appreciate your help.I am using LLBGEN Pro version 2.0

Scenario - I have a table say Dept (Master table ) and this have lot of referencial tables (around 20 tables) . And from front end (asp.net using c#) ,when I try to delete any record from Dept table I need to see if any reference exist for that record in that 20 tables and if not then allow user to delete.

Situation now - I know this deletion won't work because DB it self handles this and raises an exception.But I want to avoid DB exception or error being shown in the Aspx page as output.Instead I want to use LLBGen method to sort this out.I tried using RelationClass to get All Relations Method (GetAllReations()) with count and capacity properties.But didnt succeed in doing so.

Friend,Kindly let me know which is the right metod to do this.

thanks and regards

Raj

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 24-Sep-2008 17:08:51   

I understand from your words is that you want to notify the end user that this object can't be deleted because there exists certain related objects in the system.

For this you should perform some queries on the related tables before you call the delete method.

Something like:

SELECT Count(*) FROM someTable WHERE someFkField = xyz

Which can be performed with using the GetScalar() method.

If all the GetScalar() calls to the releated tables return Zero, then you should proceed with the delete, otherwise you should report which related tables hod some records that reference the main object to be deleted.

Otherwise if you want to save youself all this hassel, you may just delete the record and handle the exception thrown from the database, and report it back to the user in a user friendly message. (Which I normaly do to save several database calls).

Rajini
User
Posts: 2
Joined: 24-Sep-2008
# Posted on: 24-Sep-2008 17:26:00   

Hi Walaa,

Thanks for your response and appreciate your understanding of the problem.Infact I waited for long time and when I didn't get any reply on here , I tried the same thing like I catch the Exception raised from ASp and accordingly show the user with a friendly message.Anyways thanks a lot for your answer.

regards

Raj

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 24-Sep-2008 17:28:11   

Sorry about that, you have just posted your question between my support shifts. We do our best to cover this forum all through the week, but we do it in shifts with some gaps between them.

Sorry again, and glad you have worked the issue out.