Exploring the OpenAccessLinqDataSource Events
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.
The OpenAccessLinqDataSource exposes various events that could be used to customize the behavior of the control. The following are the most important events.
ContextCreated
The ContextCreated event occurs after an instance of the context type object is created. You could handle the ContextCreated event to examine the context object or to check for any exceptions that have been raised during the context initialization.
ContextCreating
The ContextCreating event occurs before an instance of the context type object is created. For more information, read How to: Set a Custom OpenAccessContext.
ContextDisposing
The ContextDisposing event occurs before disposing the context. You could handle the ContextDisposing event to dispose the object manually, or to perform cleanup that is specific to the object before the context is destroyed.
Deleted
The Deleted event occurs when a delete operation has finished. You could handle the Deleted event to catch and process any exceptions from the delete operation.
Deleting
The Deleting event occurs before a delete operation. You could handle the Deleting event to validate the object to be deleted, to change a value before the delete operation, or to cancel the delete operation. The OpenAccessLinqDataSource control passes an OpenAccessLinqDataSourceDeleteEventArgs object to the event handler for the Deleting event. The OriginalObject property contains the data that will be deleted. The OpenAccessLinqDataSourceDeleteEventArgs derives from CancelEventArgs, i.e. it is a cancelable event. You can cancel the insert operation by setting the Cancel property to True. For more information, please refer to Performing Delete Operations.
Inserted
The Inserted event occurs when an insert operation has finished. You could handle the Inserted event to catch any backend exceptions from the insert operation or to examine the values after the insert operation has finished. To access the new object, you need to examine the Result property of the OpenAccessLinqDataSourceStatusEventArgs class.
Inserting
The Inserting event occurs before an insert operation. You could handle the Inserting event to validate the object to be inserted, to change a value before the insert operation, or to cancel the insert operation. The OpenAccessLinqDataSourceInsertEventArgs object passed to the event handler for this event contains the new object to insert in the database. The OpenAccessLinqDataSourceInsertEventArgs object also exposes information about validation errors. For example, a validation error occurs if a value to be inserted does not match the type of the property in the domain class. You can retrieve the validation exceptions via the Exception property and take appropriate actions.
The Inserting event allows you to modify data before the insert operation. You need to access the NewObject property. It is of type object and you have to cast it to the type that represents the table.
The OpenAccessLinqDataSourceInsertEventArgs derives from CancelEventArgs, i.e. it is a cancelable event. You can cancel the insert operation by setting the Cancel property to True. For more information, please refer to Performing Insert Operations.
Selected
The Selected event occurs when a data retrieval operation has finished. You could handle the selected event to catch any exceptions from the data retrieval operation.
Selecting
The Selecting event occurs before a data-retrieval operation. You could handle the Selecting event in the following cases:
- Generate the query programmatically.
- Modify parameters and values for sorting, paging.
- Cancel the data-retrieval operation.
The OpenAccessLinqDataSourceSelectEventArgs object that is passed to the event handler contains the parameters for the data-retrieval operation. You can modify the parameters in the Selecting event handler before the query executes. For more information, please refer to Selecting Data.