Articles → LIGHT SWITCH 2011 → Preprocess query in lightswitch 2011

Preprocess query in lightswitch 2011




























Software requirement











Prerequisite knowledge











What is preprocess query





Scenario





Steps of execution

















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








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