Quick Objects Documentation Akal Tech Logo
Simply Group By

Glossary Item Box

Business Logic Framework - How To:

The process of creating a Group By result set is quite simple.  Simply set the ObjectMode property of the business object to GroupBy. Then specify which fields should be grouped by or aggregate functions to be used along with each field's position in the grouping.

Starting version 3.5 if you are only grouping by single field you no longer need to specify the GroupPosition.

 

1 // This sample will show you how to do a simple Group By. For the purpose of this sample  
2 // we will return Sum of all orders placed by a customer.  
3 // To achieve this we will group by the CustomerID and perform a Sum on the OrderAmount  
4 using  (Orders order =  new Orders()) 
5
6     // Setting the ObjectMode to GroupBy is the first step in indicating to the business object that you would like it to group the results.  
7     order.ObjectMode = ObjectModes.GroupBy; 
8     // Now we need to set the GroupType and GroupPosition properties of the CustomerID column  
9     order.CustomerID.GroupType = GroupTypes.GroupBy; 
10     order.CustomerID.GroupPosition = 1; 
11  
12     // Starting version 3.5 a new alternative is to use the Set method overload and perform the above in the same line of code.  
13     order.OrderAmount.Set(GroupTypes.Sum, 2); 
14     order.Find(); 
15     if (order.AffectedRecords > 0) 
16     { 
17          this.dataGridView1.DataSource = order.ResultSet; 
18          this.dataGridView1.DataMember = order.GetResultSetName(); 
19     } 
20
21  
1 ' This sample will show you how to do a simple Group By. For the purpose of this sample 
2 ' we will return Sum of all orders placed by a customer. 
3 ' To acheive this we will group by the CustomerID and perform a Sum on the OrderAmount 
4 Using order As New Orders() 
5     ' Setting the ObjectMode to GroupBy is the first step in indicating to the business object that you would like it to group the results. 
6     order.ObjectMode = ObjectModes.GroupBy 
7     ' Now we need to set the GroupType and GroupPosition properties of the CustomerID column 
8     order.CustomerID.GroupType = GroupTypes.GroupBy 
9     order.CustomerID.GroupPosition = 1 
10      
11     ' Starting version 3.5 a new alternative is to use the Set method overload and perform the above in the same line of code. 
12     order.OrderAmount.[Set](GroupTypes.Sum, 2) 
13     order.Find() 
14     If order.AffectedRecords > 0 Then 
15         Me.dataGridView1.DataSource = order.ResultSet 
16         Me.dataGridView1.DataMember = order.GetResultSetName() 
17     End If 
18 End Using