Business Logic Framework - Tutorial 14:
This tutorial shows you how to use the Strongly Typed Collections to enumerate over result set, including the ability to access the related object's data. Quick Objects use a very unique approach to providing strongly typed collection and it is suitable for even larger sets of data. The underlying data is held in a data set and is made available on demand as needed. This avoids the overhead that might be added by each object instance. For example if you wanted to enumerate over 1000 customer records, any other code generation or persistence solution will create 1000 instances of the customer class but with Quick Objects a single instance will provide you strongly typed access to 1000 records.
| 1 |
using (OrderItems oi = new OrderItems()) |
| 2 |
{ |
| 3 |
// The following line will create a join with the Products object and the result set will include Products data as well. |
| 4 |
oi.Join_ProductID_Products_Parent(); |
| 5 |
// calling the Find method will run the select statement, and it will return all records since no search criteria is specified |
| 6 |
oi.Find(); |
| 7 |
|
| 8 |
// Then we can use the List property on the oi object instance to enumerate each record in the result set. |
| 9 |
// QuickObjects takes a completely unique approach to providing a strongly typed collection compared to any other DAL product. |
| 10 |
// Instead of creating a new object for each record the same object is used to load values dynamically. This results in a much smaller |
| 11 |
// footprint, as one object instance can be used to enumerate over any number of records. |
| 12 |
int top = this.Top; |
| 13 |
foreach (OrderItems item in oi.List) |
| 14 |
{ |
| 15 |
// Now you can use either item or the oi variable (as they both point to the same object instance.) |
| 16 |
// All Fields that are "Visible" their values are automatically loaded and are accessible as shown below. |
| 17 |
// The following line show that you can access not only the Fields in the OrderItems but also the related object i.e. Products type (from the ProductID_Products_Parent property of the OrderItems). |
| 18 |
Label lbl = new Label(); |
| 19 |
lbl.Text = oi.ProductID_Products_Parent.ProductName.Value + " - " + oi.ProductID_Products_Parent.ProductPrice.Value.ToString() + " (Order Item ID = " + oi.OrderItemID.Value.ToString() + ")"; |
| 20 |
lbl.Top = top; |
| 21 |
top = top + 30; |
| 22 |
lbl.Width = 400; |
| 23 |
this.Controls.Add(lbl); |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 1 |
Using oi As OrderItems = New OrderItems() |
| 2 |
'The following line will create a join with the Products object and the result set will include Products data as well. |
| 3 |
oi.Join_ProductID_Products_Parent() |
| 4 |
'calling the Find method will run the select statement, and it will return all records since no search criteria is specified |
| 5 |
oi.Find() |
| 6 |
'Then we can use the List property on the oi object instance to enumerate each record in the result set. |
| 7 |
'QuickObjects takes a completely unique approach to providing a strongly typed collection compared to any other DAL product. |
| 8 |
'Instead of creating a new object for each record the same object is used to load values dynamically. This results in a much smaller |
| 9 |
'footprint, as one object instance can be used to enumerate over any number of records. |
| 10 |
Dim top As Int32 = Me.Top |
| 11 |
Dim item As OrderItems |
| 12 |
For Each item In oi.List |
| 13 |
'Now you can use either item or the oi variable (as they both point to the same object instance.) |
| 14 |
'All Fields that are "Visible" their values are automatically loaded and are accessible as shown below. |
| 15 |
'The following line show that you can access not only the Fields in the OrderItems but also the related object i.e. Products type (from the ProductID_Products_Parent property of the OrderItems). |
| 16 |
Dim lbl As Label = New Label() |
| 17 |
lbl.Text = oi.ProductID_Products_Parent.ProductName.Value & " - " & oi.ProductID_Products_Parent.ProductPrice.Value.ToString() & " (Order Item ID = " & oi.OrderItemID.Value.ToString() & ")" |
| 18 |
lbl.Top = top |
| 19 |
top = top + 30 |
| 20 |
lbl.Width = 400 |
| 21 |
Me.Controls.Add(lbl) |
| 22 |
Next |
| 23 |
End Using |
| 24 |
|