/// <summary> /// Handles the EntityUpdating event of the ProductsDS control. /// Used to trap the entity fields errors at the current ProductEntity /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="SD.LLBLGen.Pro.ORMSupportClasses.CancelableDataSourceActionEventArgs"/> instance containing the event data.</param> protected void ProductsDS_EntityUpdating(object sender, CancelableDataSourceActionEventArgs e) { // the entity involved ProductEntity entityToEvaluate = (ProductEntity)e.InvolvedEntity; // Retrieve the fields errors from the entity. This will return a semicolon-separated list containing the info. string errors = entityToEvaluate.GetEntityFieldsErrors(); // there are errors, so cancel the update so the user can fix them. if (errors != string.Empty) { e.Cancel = true; ShowEntityErrors(errors); } else { HideEntityErrorControls(); } }
/// <summary> /// Handles the EntityDeleting event of the LLBLGenProDataSource. /// Used to delete order details related to the order being deleted. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void OrdersDS_EntityDeleting(object sender, CancelableDataSourceActionEventArgs e) { //Get the Order to be deleted OrderEntity orderToDelete = (OrderEntity)e.InvolvedEntity; try { // directly delete all order details with a matching OrderId DataAccessAdapter adapter = new DataAccessAdapter(); adapter.DeleteEntitiesDirectly("OrderDetailEntity", new RelationPredicateBucket(OrderDetailFields.OrderId == orderToDelete.OrderId)); } // All exceptions are swallowed here, it's outside the scope of this example to handle different exceptions. // If you are going to use this code in production, it's a best practice to add proper exception handling. catch { // cancel the Order deletion, if anything wrong happened while deleting its related order-details. e.Cancel = true; } }