Quick Objects Documentation Akal Tech Logo
Performing Complex Search with Related Objects

Glossary Item Box

Business Logic Framework - Tutorial 7:

Our seventh tutorial shows you how to run searches on related tables. The objective is to allow the user to specify an amount and the business object will find all the orders that contain a item that is priced higher than the specified amount. Essentially, if the user specifies 69.99 then any order that contains an item priced higher than that will be included in the result set. We however do not want to include duplicate records for an order in case an order has more than one item priced higher than the specified amount.

Here is the C# code that is used to achieve the desired results:

 

1 if (this.TextBox_MinimumItemAmount.Text.Trim().Length > 0)  
2 {  
3     using (Orders orders = new Orders())  
4     {  
5     // Setting the ObjectMode on the customer object to ObjectModes.Search  
6     // tells the customer object to change its field's UseInSearch property to true  
7     // when a value is assigned to the field's value property.  
8         orders.ObjectMode = Akal.QuickObjects.ObjectBase.ObjectModes.Search;  
9         orders.Join_OrderID_OrderItems_Child();  
10           
11         // since we don't want to see any fields from OrderItems object, we set the Visible property  
12         // of the OrderID_OrderItems_Child object to false.  
13         orders.OrderID_OrderItems_Child.Visible = false;  
14  
15         // By using the Parse method we are assigning the value specified by the user in TextBox_MinimumItemAmount  
16         // to the ItemAmount property of the OrderID_OrderItems_Child object.  
17         // Since the ObjectMode of the Orders object was set to ObjectModes.Search and the OrderID_OrderItems_Child was joined afterwards  
18         // the OrderID_OrderItems_Child's ObjectMode was also set to ObjectModes.Search at the time of Join creation between the two objects.  
19         orders.OrderID_OrderItems_Child.ItemAmount.Parse(this.TextBox_MinimumItemAmount.Text);  
20           
21         // We have great amount of control over our search criteria. One very good example is the ability to  
22         // modify the Operator of any field so that the business object uses this operator instead of using the default equality operator.  
23         orders.OrderID_OrderItems_Child.ItemAmount.Operator = " > ";  
24           
25         // OnlyDistinct property is very useful if you want to only return rows that are unique.  
26         // This is equivalent to specifying a DISTINCT clause in the SQL statement.  
27         orders.OnlyDistinct = true;  
28           
29         orders.Find();  
30         if (orders.AffectedRecords > 0)  
31         {  
32             this.GridView.DataSource = orders.ResultSet;  
33             this.GridView.DataMember = orders.GetResultSetName();  
34         }  
35         else 
36         {  
37             this.GridView.DataSource = "";  
38         }  
39     }  
40 }  
41  
1 If Me.TextBox_MinimumItemAmount.Text.Trim().Length > 0 Then 
2     Using orders As Orders = New Orders()  
3         orders.ObjectMode = Akal.QuickObjects.ObjectBase.ObjectModes.Search  
4         orders.Join_OrderID_OrderItems_Child()  
5  
6         ' since we don't want to see any fields from OrderItems object, we set the Visible property  
7         ' of the OrderID_OrderItems_Child object to false.  
8         orders.OrderID_OrderItems_Child.Visible = False 
9  
10         ' By using the Parse method we are assigning the value specified by the user in TextBox_MinimumItemAmount  
11         ' to the ItemAmount property of the OrderID_OrderItems_Child object.  
12         ' Since the ObjectMode of the Orders object was set to ObjectModes.Search and the OrderID_OrderItems_Child was joined afterwards  
13         ' the OrderID_OrderItems_Child's ObjectMode was also set to ObjectModes.Search at the time of Join creation between the two objects.  
14         orders.OrderID_OrderItems_Child.ItemAmount.Parse(Me.TextBox_MinimumItemAmount.Text)  
15  
16         ' We have great amount of control over our search criteria. One very good example is the ability to  
17         ' modify the Operator of any field so that the business object uses this operator instead of using the default equality operator.  
18         orders.OrderID_OrderItems_Child.ItemAmount.Operator = " > " 
19  
20         ' OnlyDistinct property is very useful if you want to only return rows that are unique.  
21         ' This is equivalent to specifying a DISTINCT clause in the SQL statement.  
22         orders.OnlyDistinct = True 
23  
24         orders.Find()  
25         If orders.AffectedRecords > 0 Then 
26             Me.GridView.DataSource = orders.ResultSet  
27             Me.GridView.DataMember = orders.GetResultSetName()  
28         Else 
29             Me.GridView.DataSource = "" 
30         End If 
31     End Using  
32 End If 
33