How to: Handle Query Events
For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.
You can customize your application by writing code that runs when certain query-related events occur. For example, you can extend a query by adding code to an event that occurs when the query is being processed by LightSwitch.
Open a query by double clicking it in the Solution Explorer.
The query designer opens.
Click the arrow next to the Write Code button at the top of the Query Designer and select the method that you want to override. The methods that can be handled by your application appear in the table below.
The Code Editor opens.
Place your cursor in the method that was just created and type the code that you want to run when the event occurs.
The following table lists the query events that can be handled by your application:
|<QueryName>_PreProcessQuery()||Called when the query is being formed. Enables you to further customize a query. Runs on the server.|
|Query_Executing()||Called just before executing the query. Runs on the server.|
|Query_Executed()||Called just after successfully executing the query. Runs on the server.|
|Query_ExecuteFailed()||Called after a query fails to run. Runs on the server.|
|<QueryName>_CanExecute()||Called prior to executing the query in order to check permissions for the current user. Runs on the server.|