Result Representation

This example shows how to modify the query output without effecting the objects in the database. Store Pilots function is used to fill in the database.

SelectAndChangePilots

SimpleExamples.cs: SelectAndChangePilots
01private static void SelectAndChangePilots() 02 { 03 IObjectContainer container = Database(); 04 if (container != null) 05 { 06 try 07 { 08 IList<Pilot> result = container.Query<Pilot>(delegate(Pilot pilot) 09 { 10 // Add ranking to the pilots during the query. 11 // Note: pilot records in the database won't 12 // be changed!!! 13 if (pilot.Points <= 5) 14 { 15 pilot.Name = pilot.Name + ": weak"; 16 } 17 else if (pilot.Points > 5 18 && pilot.Points <= 15) 19 { 20 pilot.Name = pilot.Name + ": average"; 21 } 22 else if (pilot.Points > 15) 23 { 24 pilot.Name = pilot.Name + ": strong"; 25 } 26 return true; 27 28 }); 29 ListResult(result); 30 } 31 catch (Exception ex) 32 { 33 System.Console.WriteLine("System Exception: " + ex.Message); 34 } 35 finally 36 { 37 CloseDatabase(); 38 } 39 } 40 }
SimpleExamples.vb: SelectAndChangePilots
01Private Shared Sub SelectAndChangePilots() 02 Dim container As IObjectContainer = Database() 03 If Not container Is Nothing Then 04 Try 05 Dim result As IList(Of Pilot) = container.Query(Of Pilot)(AddressOf RankPilotsAndMatch) 06 ListResult(result) 07 Catch ex As Exception 08 System.Console.WriteLine("System Exception: " + ex.Message) 09 Finally 10 CloseDatabase() 11 End Try 12 End If 13 End Sub
SimpleExamples.vb: RankPilotsAndMatch
01Private Shared Function RankPilotsAndMatch(ByVal p As Pilot) As Boolean 02 ' Add ranking to the pilots during the query. 03 ' Note: pilot records in the database won't 04 ' be changed!!! 05 If p.Points <= 5 Then 06 p.Name = p.Name + ": weak" 07 ElseIf p.Points > 5 AndAlso p.Points <= 15 Then 08 p.Name = p.Name + ": average" 09 ElseIf p.Points > 15 Then 10 p.Name = p.Name + ": strong" 11 End If 12 Return True 13 End Function