/// <summary> /// Summary description for SQLTracGrp. /// </summary> public partial class SQLTracGrp { ....... protected override bool HookPreDeleteEntity(SQLTracGrpEntity entity) { bool bReturn = base.HookPreDeleteEntity(entity); if (bReturn) { // check to see if this type is used by a group or resource string sCommand = "[dbo].[sp_SQLTrac_CanDeleteGrp]"; if ((int)this.ExecSprocScalar(sCommand, this.CreateParameter("@GrpID", (object)entity.GrpID, DbType.Int16)) == 0 ) { bReturn = false; } } return bReturn; } }As per the documentation, this code gets called by DeleteEnity() prior to the business object attempting to delete the record. If the stored procedures finds a FK reference to this record in the subordinate records, HookPreDeleteEntity() returns false and the delete is canceled.
protected override bool HookPreDeleteEntity(SQLTracGrpEntity entity) { bool bReturn = base.HookPreDeleteEntity(entity); if (bReturn) { // check to see if this type is used by a group or resource string sCommand = "[dbo].[sp_SQLTrac_CanDeleteGrp]"; if ((int)this.ExecSprocScalar(sCommand, this.CreateParameter("@GrpID", (object)entity.GrpID, DbType.Int16)) == 0 ) { this.OnDeleteFKBlock(); // fires a custom event handler bReturn = false; } } return bReturn; }But if there is already a better way built into the framework, why re-invent the wheel?