Skip to content

Conditional Delivery Of Deleted Objects

Consider a data table called Order. The table contains a column named orderAmount. The code below adds a listener for the delete event for the Order table.

var orderEventHandler = Backendless.Data.Of( "Order" ).RT();

orderEventHandler.AddDeleteListener( "orderAmount > 1000", deletedOrder =>
{
    Console.WriteLine( $"an Order object has been deleted in the database. Object ID - {deletedOrder["objectId"]}");
} );

Assume the following class represents objects from the Order table:

public class Order
{
  public string ObjectId{ get; set; }
  public string OrderName{ get; set; }
  public double OrderAmount{ get; set; }
}
Then the following code will register an event listener for any orders to be deleted where OrderAmount is greater than 1000:
var orderEventHandler = Backendless.Data.Of<Order>().RT();

orderEventHandler.AddDeleteListener( "OrderAmount > 1000", deletedOrder =>
{
    Console.WriteLine( $"an Order object has been deleted in the database. Object ID - {deletedOrder.ObjectId}");
} );

The event listener will receive only the deleted Order objects with the order amount exceeding 1000. This is achieved with the first argument in the AddDeleteListener method. The argument is a where clause condition, which references the orderAmount column and requests that the real-time database sends only the matching objects. The second argument is a callback object which will receive any deleted object which matches the where clause condition. Notice the argument of the delegate function method is the actual object deleted from the database.

For more information about the whereClause syntax, see the Condition Syntax section of the guide.