Business Logic Framework - How To:
Deleting multiple records at a time is very simple task with Quick Objects. The process is similar to specifying a search criteria for Find method. Once the search criteria is specified calling the BulkDelete method performs the actual delete. For search criteria you can even specify values for "joined" objects and only a single SQL statement is produced and used by the Business Logic Framework to achieve the desired results.
![]() |
Note: We recommend that you use caution while using BulkUpdate and BulkDelete methods as they can modify/delete many records at a time, and if wrong criteria is specified by mistake the result can be disastrous. |
Target of the following code is to delete orders that are older than 60 days.
Example 1: Delete record with search criteria in single table.
| using (Orders o = new Orders()) | |
| { | |
| o.ObjectMode = ObjectModes.Search; | |
| o.OrderDate.Value = DateTime.UtcNow.AddDays(-60); | |
| o.OrderDate.Operator = Operators.LessThan; | |
| if (o.BulkDelete()) | |
| { | |
| MessageBox.Show(o.AffectedRecords.ToString() + " orders older than 60 days have been deleted!"); | |
| } | |
| else | |
| { | |
| MessageBox.Show("Old orders could not be deleted. Error: " + o.ErrorString); | |
| } | |
| } | |
| Using o As Orders = New Orders() | |
| o.ObjectMode = Akal.QuickObjects.ObjectBase.ObjectModes.Search | |
| o.OrderDate.Value = DateTime.UtcNow.AddDays(-60) | |
| o.OrderDate.Operator = Operators.LessThan | |
| If o.BulkDelete() Then | |
| MessageBox.Show(o.AffectedRecords.ToString() & " orders older than 60 days have been deleted!") | |
| Else | |
| MessageBox.Show("Old orders could not be deleted. Error: " & o.ErrorString) | |
| End If | |
| End Using | |
Example 2: Delete multiple records by specifying search criteria on multiple related tables.
| // In this case we are deleting all orders placed by customers that have been a customer for longer than 6 months. | |
| // Also if the orders contain any item whose value is greater than 100. | |
| using (Orders o = new Orders()) | |
| { | |
| o.ObjectMode = ObjectModes.Search; | |
| o.CreateJoinWith_CustomerID_Customers_Parent_Obj(); | |
| o.CustomerID_Customers_Parent_Obj.CustomerSince.Value = DateTime.UtcNow.AddMonths(-6); | |
| o.CustomerID_Customers_Parent_Obj.CustomerSince.Operator = Operators.LessThan; | |
| o.CreateJoinWith_OrderID_OrderItems_Child_Obj(); | |
| o.OrderID_OrderItems_Child_Obj.ItemAmount.Value = 100; | |
| o.OrderID_OrderItems_Child_Obj.ItemAmount.Operator = Operators.GreaterThan; | |
| if (o.BulkDelete()) | |
| { | |
| MessageBox.Show(o.AffectedRecords.ToString() + " orders older than 60 days have been deleted!"); | |
| } | |
| else | |
| { | |
| MessageBox.Show("Old orders could not be deleted. Error: " + o.ErrorString); | |
| } | |
| } | |
| ' In this case we are deleting all orders placed by customers that have been a customer for longer than 6 months. | |
| ' Also if the orders contain any item whose value is greater than 100. | |
| Using o As Orders = New Orders() | |
| o.ObjectMode = ObjectModes.Search | |
| o.Join_CustomerID_Customers_Parent() | |
| o.CustomerID_Customers_Parent.CustomerSince.Value = DateTime.UtcNow.AddMonths(-6) | |
| o.CustomerID_Customers_Parent.CustomerSince.Operator = Operators.LessThan | |
| o.Join_OrderID_OrderItems_Child() | |
| o.OrderID_OrderItems_Child.ItemAmount.Value = 100 | |
| o.OrderID_OrderItems_Child.ItemAmount.Operator = Operators.GreaterThan | |
| If o.BulkDelete() Then | |
| MessageBox.Show(o.AffectedRecords.ToString() & " orders older than 60 days have been deleted!") | |
| Else | |
| MessageBox.Show("Old orders could not be deleted. Error: " & o.ErrorString) | |
| End If | |
| End Using | |
See also:

