I have described in my previous article LightSwitch Basic Application about how easily we can create a LightSwitch application using Visual Studio LightSwitch 2012.
Introduction
This article describes how to add, remove and modify a query. We also describe filtering, sorting and the use of parameters.
A query helps in providing necessary information of an application that is developed by a user.
1. Add a Query
Step 1
First, open the Solution Explorer.
Image 1
Step 2
In Solution Explorer, expand the "Data Sources". We will see our Datatable (ContactTable). Right-click on the table; we will have the "Add Query" option.
Image 2
Step 3
The "Query1" property window will be displayed . Query1 can be renamed in the Properties window.
Image 3
Step 4
Click on the Query Option, a query is added to the Solution Explorer and a query opens in the "Query Designer." Suppose, a Query1 is added to the "ContactTables" as shown.
Image 4
Step 5
As we hover over "Add Filter" we will see a add new filter condition.
Image 5
Step 6
Click on the "Add Filter" Button. It will show the following.
Image 6
Step 7
In the drop-down list we can choose any of the options. Depending on the choice, we can also add parameters.
Image 7
Step 8
After selecting the data from the drop-down list we have:
Image 8
Step 9
Now we will sort the list as it is always important to display data to the user in a sorted manner, either alphabetically or in some other way. For that click on the "Add Sort" Button. It will show the following.
Image 9
Step 10
In the following step we will click on "Add parameter".
Image 10
2. Remove a Query
First, open the Solution Explorer, expand the Data Source; we will see our "ContactTable" on expanding the Data Source as shown above. Then we "Add Query". We will have a query. Right-click the query that you want to remove, and then click "Delete".
Image 11
3. Modify a Query
Open the Solution Explorer, expand the Data Source; we will see our "ContactTable" on expanding the Data Source as shown above. Then we "Add Query". We will have a query.
We can perform two operations to modify a Query:
- Right-click the query that you want to modify, and then click Rename.
- Double-click on the query. The query opens in the Query Designer.
Image 11