QuickObjects.ObjectBase Send comments on this topic.
BulkDelete Method
See Also  Example
Akal.QuickObjects.ObjectBase Namespace > BaseBusinessObject Class : BulkDelete Method

BulkDelete

You can delete one or more records by specifying search criteria. The search criteria can include multiple related objects just like you would specify criteria for the Find method.

Please Note: If you do not specify any search criteria you will end up deleting all records in the table.

Syntax

C# 
public virtual bool BulkDelete()

Return Value

True if the BulkUpdate was successful. You can see the AffectedRecords property to find out how many records were updated.

Example

You can delete many records at the same time in a single object.
C#Copy Code
// Delete all orders that are older than 60 days. 
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("Orders could not be deleted. Error: " + o.ErrorString); 
    } 

    
In addition to search criteria on the table where records are being deleted you can also specify criteria on the related tables. The process is very simple, just create the joins and set the UseInSearch to true for the fields that you would like included in the search.
C#Copy Code
// 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.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()) 
    { 
        MessageBox.Show(o.AffectedRecords.ToString() + " orders have been deleted!"); 
    } 
    else 
    { 
        MessageBox.Show("Old orders could not be deleted. Error: " + o.ErrorString); 
    } 

    

Requirements

Target Platforms: .NET Framework 1.1 or .NET Framework 2.0

See Also