Data Access has been discontinued. Please refer to this page for more information.

How to: Bulk Delete Artificial Types

This article is relevant to entity models that utilize the deprecated Visual Studio integration of Telerik Data Access. The current documentation of the Data Access framework is available here.

Bulk deleting objects of artificial types is the same as bulk deleting objects of regular entity types.

A good approach for working with bulk operations and artificial types is to take advantage over Dynamic LINQ.

In order to perform a bulk delete operation on an artificial type, you can use the following workflow:

To use the DeleteAll() method you need to add a using / Imports clause to the Telerik.OpenAccess namespace in your code.

  1. Define a query that will be the source for the delete operation
  2. Perform the operation

    using System.Linq.Dynamic;            
    using Telerik.OpenAccess;
    using (EntitiesModel context = new EntitiesModel())
        //Define a query that is the source of the operation. 
        //All matching elements will be affected by the DeleteAll operation
        var query = context.GetAll("Car").Where("CarYear < {0}", 1990)
        //Perform a bulk delete operation
        int deleted = query.DeleteAll(); 
        Console.WriteLine("deleted cars: {0}", deleted);

    Due to limitations in VB the extension methods on objects need to be called as static methods.

    Imports System.Linq.Dynamic            
    Imports Telerik.OpenAccess        
    Using context = New EntitiesModel()
        ' Define a query that is the source of the operation. 
        ' All matching elements will be affected by the DeleteAll operation
        Dim query As IQueryable(Of Car) = context.GetAll("Car").Where("CarYear < {0}", 1990)
        ' Perform a bulk delete operation
        Dim deleted = query.DeleteAll()
        Console.WriteLine("deleted cars {0}", deleted) 
    End Using 

That operation will attempt to remove all cars produced before 1990 from the SofiaCarRental database. Any violations of the referential integrity in the storage model will be reported to the user with an InvalidOperationException exception and the transcation will be rolled back.

Optionally, you can adjust the command timeout on bulk operation level as described in How to: Set The Timeout / On Query Level, if the execution of the commands it contains is expected to take long time. By default, it is the one specified in Runtime Configuration. If the command exceeds the timeout it will be terminated and a backend specific exception will be thrown.