/// <summary> /// Method to validate the containig entity right beforethe entity's delete action will take place. /// </summary> /// <param name="involvedEntity">The involved entity.</param> public override void ValidateEntityBeforeDelete(IEntityCore involvedEntity) { // variable to collect errors StringBuilder sbExceptionMessage = new StringBuilder(); // customer to validate. Cast depends upon the entity you are validating. CustomerEntity toValidate = (CustomerEntity)involvedEntity; #region Check validation rules. /// Can't delete a customer that has orders related. /// Note: this assumes that the orders have been prefetched with the involvedEntity, /// so we can avoid the trip to DB and check this rule before DB throws an error. if (toValidate.Orders.Count != 0) { // add the error info to the message sbExceptionMessage.Append(CUSTOMER_INVALID_DELETE_ERROR_MESSAGE + DELIMITER); } // -- add more validations -- // ... #endregion // get the errors collected string strExceptionMessage = sbExceptionMessage.ToString(); // Do exist any break rule in this entity? if (strExceptionMessage != string.Empty) { // set error info so we can access that outside toValidate.SetEntityError(strExceptionMessage); // throws an exception with all the breaking rules info throw new ORMEntityValidationException(strExceptionMessage, toValidate); } // if everything is ok, we reach this point, so lets the base class do its work base.ValidateEntityBeforeDelete(involvedEntity); }