|
Build the Order Object The Order business entity class is a container for the NorthwindCS sample database's Orders and Order Details data for a specific order number. Procedural code in the GetOrder data access logic component (DALC) sets initial Order and Order Details member values. Class and member names don't need to be identical to table and column names. A business process component (BPC) alters the member values and invokes the UpdateOrder DALC to modify table data. Another BCP uses the InsertOrder DALC to add new order data. This VB.NET code defines the Orders and OrderDetails classes: Public Class Order
Public OrderID As Int32
Public CustomerID As String
Public EmployeeID As Int32
Public OrderDate As Date
Public RequiredDate As Date
Public ShippedDate As Date
Public ShipVia As Int32
Public Freight As Decimal
Public ShipName As String
Public ShipAddress As String
Public ShipCity As String
Public ShipRegion As String
Public ShipPostalCode As String
Public ShipCountry As String
Public OrderDetails(24) As _
OrderDetail
End Class
Public Class OrderDetail
Public OrderID As Int32
Public ProductID As Int32
Public UnitPrice As Decimal
Public Quantity As Int16
Public Discount As Decimal
End Class
For simplicity, I initialized the array of small OrderDetail objects to 25 elements, which the code later ReDim Preserves to the actual number of Order Details records. I also modified NorthwindCS's Order Details table to substitute decimal(5,3) for real as the Discount column's data type to eliminate rounding errors that don't appear in DataGrids but show up in real representations. InfoPath is a typical client application that has problems handling fractional real values. You must persist the Order business entity by serializing the Order instance to a well-formed, hierarchical XML document in order to preserve an audit trail, support disconnected clients, or participate in document-oriented workflow systems. XML Web services also serialize class instances to generate the SOAP payload; Web service consumers deserialize them to a new instance. (This process is called dehydrating and rehydrating an object.) This is a serialized Order document: <Order>
<OrderID>974824</OrderID>
<CustomerID>BOLID</CustomerID>
<EmployeeID>4</EmployeeID>
<OrderDate>
1996-10-10T00:00:00.0000000-07:00
</OrderDate>
<RequiredDate>
1996-11-07T00:00:00.0000000-08:00
</RequiredDate>
<ShippedDate>
1996-11-07T00:00:00.0000000-08:00
</ShippedDate>
<ShipVia>2</ShipVia>
<Freight>77.92</Freight>
<ShipName>
Bólido Comidas preparadas
</ShipName>
<ShipAddress>C/ Araquil, 67</ShipAddress>
<ShipCity>Madrid</ShipCity>
<ShipRegion />
<ShipPostalCode>28023</ShipPostalCode>
<ShipCountry>Spain</ShipCountry>
<OrderDetails>
<OrderDetail>
<OrderID>974824</OrderID>
<ProductID>4</ProductID>
<UnitPrice>17.6</UnitPrice>
<Quantity>24</Quantity>
<Discount>0</Discount>
</OrderDetail>
<OrderDetail>
<OrderID>974824</OrderID>
<ProductID>57</ProductID>
<UnitPrice>15.6</UnitPrice>
<Quantity>16</Quantity>
<Discount>0</Discount>
</OrderDetail>
</OrderDetails>
</Order >
Some NorthwindCS orders have null values in the ShippedDate field. .NET generates XSD schemas that require values for data types other than xsd:string. The XML Schema Part 2: Datatypes specification doesn't provide a representation for the null date value, so the choice is implementation-specific. Microsoft uses 0001-01-00T00:00:00.0000000-ZZ:00, where -ZZ is the computer's time-zone setting (-08 for Pacific standard time). When the UpdateOrder and InsertOrder DALCs detect a date value of 1/1/0001, they return a NULL value to the Orders table. A change from daylight-saving to standard time accounts for the differences in the OrderDate and RequiredDate/ShippedDate values in the sample XML document. |