How to prevent parent record being deleted?


Author
Message
Wang Tong Yin
Wang Tong Yin
StrataFrame Novice (61 reputation)StrataFrame Novice (61 reputation)StrataFrame Novice (61 reputation)StrataFrame Novice (61 reputation)StrataFrame Novice (61 reputation)StrataFrame Novice (61 reputation)StrataFrame Novice (61 reputation)StrataFrame Novice (61 reputation)StrataFrame Novice (61 reputation)
Group: Forum Members
Posts: 25, Visits: 46
In my application has two business objects, CustomerBO and OrderBO. CustomerBO  is mapped to customer table and OrderBO is mapped to order table. CustomerBO is the parent business object of OrderBO. The reference integrity of customer and order tables not set in the database.  I want to prevent the application from deleting the record in customerBO if the record is referenced by orderBO records. May I know how the business object can prevent this deletion?
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
You can write a shared method on the OrdersBO that will get the count of the records within the database that have the given CustomersBO as their parent.  Then, simply handle the BeforeDelete event of the CustomersBO and if the count of the method returns > 0 then, set e.Cancel = True and show an error message.  That's the most efficient way to do it.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search