Articles → LIGHT SWITCH 2011 → Preprocess Query In Lightswitch 2011

Preprocess Query In Lightswitch 2011






Software Requirement




  1. Visual studio 2010 is installed on your machine.
  2. Visual Studio 2010 service pack 1 is installed on your machine.
  3. Microsoft Visual Studio Light switch 2011 is installed on your machine.

Prerequisite Knowledge




  1. Basics about lightswitch.
  2. How to create screens in lightswitch?
  3. How to create tables in lightswitch?

What Is Preprocess Query





Scenario





Steps Of Execution




  1. Create a new project
  2. Add tables
  3. Add screen
  4. Add data to tables
  5. Write preprocess query



Create A New Project




Picture showing the project structure of the lightswitch application in visual studio
Click to Enlarge


Add Tables




Picture showing the Employee table in the lightswitch table designer
Click to Enlarge

Picture showing the SortSettings table in the lightswitch table designer
Click to Enlarge


Add Screen




Picture showing adding 2 screens in the lightswitch application
Click to Enlarge


Add Data To Tables




Picture showing adding the data in both the screens
Click to Enlarge


Write Preprocess Query




  1. Open Employees table (from Data Sources – ApplicationData)
  2. From the ‘Write Code’ option select ‘Employees_All_PreprocessQuery’ as shown in figure below
  3. Picture showing selecting an event for preprocess query in lightswitch
    Click 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


Picture showing the output of preprocess query in lightswitch
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Wednesday, April 3, 2013

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250