Articles → LIGHT SWITCH 2011 → Preprocess Query In Lightswitch 2011
Preprocess Query In Lightswitch 2011
Software Requirement
 
- Visual studio 2010 is installed on your machine.
- Visual Studio 2010 service pack 1 is installed on your machine.
- Microsoft Visual Studio Light switch 2011 is installed on your machine.
Prerequisite Knowledge
 
- Basics about lightswitch.
- How to create screens in lightswitch?
- How to create tables in lightswitch?
What Is Preprocess Query
 
Scenario
 
Steps Of Execution
 
- Create a new project
- Add tables
- Add screen
- Add data to tables
- Write preprocess query
Create A New Project
 
Click to Enlarge
Add Tables
 
Click to Enlarge
Click to Enlarge
Add Screen
 
Click to Enlarge
Add Data To Tables
 
Click to Enlarge
Write Preprocess Query
 
- Open Employees table (from Data Sources – ApplicationData)
- From the ‘Write Code’ option select ‘Employees_All_PreprocessQuery’ as shown in figure belowClick to Enlarge
partial void Employees_All_PreprocessQuery(ref IQueryable < Employee > query) {
  var setting = this.DataWorkspace.ApplicationData.SortSettingsSet.FirstOrDefault();
  if (setting != null) {
    if (setting.SortFieldName.CompareTo("NAME") == 0) {
      query = query.OrderBy(x => x.EmployeeName);
    } else if (setting.SortFieldName.CompareTo("DOJ") == 0) {
      query = query.OrderBy(x => x.DOJ);
    }
  }
}
Output
 
Click to Enlarge
| Posted By  - | Karan Gupta | 
|  | 
| Posted On  - | Wednesday, April 3, 2013 |