StrataFrame Forum

How to prevent parent record being deleted?

http://forum.strataframe.net/Topic1784.aspx

By Wang Tong Yin - 7/9/2006

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?
By StrataFrame Team - 7/10/2006

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.