Database Reference
In-Depth Information
Console.WriteLine("Total Rentals: {0}",
((int)totalRentals.Value).ToString());
Console.WriteLine("Total Payments: {0}",
((decimal)totalPayments.Value).ToString("C"));
}
The following is the output of the code in Listing 10-8:
Rental Activity for 5/7/2013
Vehicles Rented
2013 Toyota Camry
2013 Chevrolet Corvette
Total Rentals: 2
Total Payments: $200.00
How It Works
When we updated the model with the GetVehiclesWithRentals stored procedure, the wizard updated the store
model with the stored procedure. By importing the function (in Step 2), we updated the conceptual model. The result
is that the stored procedure is exposed as the GetVehiclesWithRentals() method, which has a signature semantically
similar to the stored procedure.
There is one important thing to note when calling the GetVehiclesWithRentals() method: the returned entity
collection must be materialized before the output parameters will become available. This should not be too surprising
to those who have used multiple result sets in ADO.NET. The data reader must be advanced (with the NextResult()
method) to the next result set. Similarly, the entire returned entity collection must be accessed or disposed before the
output parameters can be accessed.
In our example, it is not enough to materialize the first vehicle for the output parameters to become available.
The entire collection must be materialized. This means moving the lines that print the total rentals and total payments
to a position after the foreach loop. Alternatively, we could materialize the entire collection with the ToList()
method and then iterate through the list. This would allow us to access the output parameters prior to iterating
through the collection.
10-3. Returning a Scalar Value Result Set
Problem
You want to use a stored procedure that returns a result set containing a single scalar value.
Solution
Let's say you have a model like the one shown in Figure 10-2 .
 
 
Search WWH ::




Custom Search