barcodelib c# Returning Output Parameters in Font

Generator QR in Font Returning Output Parameters

10-2. Returning Output Parameters
Generate Denso QR Bar Code In None
Using Barcode drawer for Font Control to generate, create QR Code image in Font applications.
www.OnBarcode.com
Generating Code 128 Code Set B In None
Using Barcode creation for Font Control to generate, create ANSI/AIM Code 128 image in Font applications.
www.OnBarcode.com
Problem
UCC.EAN - 128 Drawer In None
Using Barcode printer for Font Control to generate, create EAN 128 image in Font applications.
www.OnBarcode.com
Encoding Barcode In None
Using Barcode creation for Font Control to generate, create Barcode image in Font applications.
www.OnBarcode.com
You want to retrieve values from one or more output parameters of a stored procedure.
QR Code ISO/IEC18004 Generation In None
Using Barcode generation for Font Control to generate, create QR Code 2d barcode image in Font applications.
www.OnBarcode.com
PDF-417 2d Barcode Creation In None
Using Barcode creation for Font Control to generate, create PDF-417 2d barcode image in Font applications.
www.OnBarcode.com
Solution
Barcode Maker In None
Using Barcode generator for Font Control to generate, create Barcode image in Font applications.
www.OnBarcode.com
2/5 Interleaved Creator In None
Using Barcode printer for Font Control to generate, create Uniform Symbology Specification ITF image in Font applications.
www.OnBarcode.com
Let s say you have a model like the one in Figure 10-3.
Reading Quick Response Code In Visual Studio .NET
Using Barcode scanner for .NET framework Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
QR Code 2d Barcode Encoder In None
Using Barcode drawer for Office Word Control to generate, create QR Code image in Word applications.
www.OnBarcode.com
STORED PROCEDURES
Scan EAN13 In VS .NET
Using Barcode recognizer for .NET framework Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
Universal Product Code Version A Decoder In VB.NET
Using Barcode scanner for Visual Studio .NET Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
Figure 10-3. A simple model for vehicle rental For a given date, you want to know the total number of rentals, the total rental payments made, and the vehicles rented. The stored procedure in Listing 10-5 is one way to get the information we want. Listing 10-5. A stored procedure for the vehicles rented, the number of rentals, and the total rental payments create procedure [chapter10].[GetVehiclesWithRentals] (@date date, @TotalRentals int output, @TotalPayments decimal(18,2) output) as begin select @TotalRentals = COUNT(*), @TotalPayments = SUM(payment) from chapter10.Rental where RentalDate = @date select distinct v.* from chapter10.Vehicle v join chapter10.Rental r on v.VehicleId = r.VehicleId end To use the stored procedure in Listing 10-5 in the model, do the following. 1. Right-click the design surface and select Update Model From Database. In the dialog box, select the GetVehiclesWithRentals stored procedure. Click Finish to add the stored procedure to the model. Right-click the design surface and select Add Function Import. Select the GetVehiclesWithRentals stored procedure from the Stored Procedure Name drop-down. In the Function Import Name text box, enter GetVehiclesWithRentals. This will be the name used for the method in the model. Select the Entities Return Type and select Vehicle in the drop-down. Click OK. Follow the pattern in Listing 10-6 to use the GetVehiclesWithRentals stored procedure.
QR Generator In None
Using Barcode maker for Excel Control to generate, create QR Code image in Excel applications.
www.OnBarcode.com
Generate QR Code JIS X 0510 In Java
Using Barcode creator for Eclipse BIRT Control to generate, create QR Code ISO/IEC18004 image in BIRT reports applications.
www.OnBarcode.com
STORED PROCEDURES
Recognizing Code 3/9 In None
Using Barcode scanner for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
Code 128 Code Set A Creation In .NET Framework
Using Barcode drawer for ASP.NET Control to generate, create USS Code 128 image in ASP.NET applications.
www.OnBarcode.com
Listing 10-6. Querying the model using the GetVehiclesWithRentals stored procedure via the GetVehiclesWithRentals() method using (var context = new EFRecipesEntities()) { var car1 = new Vehicle { Manufacturer = "Toyota", Model = "Camry", Year = 2010 }; var car2 = new Vehicle { Manufacturer = "Chevrolet", Model = "Corvette", Year = 2010 }; var r1 = new Rental { Vehicle = car1, RentalDate = DateTime.Parse("2/2/2010"), Payment = 59.95M }; var r2 = new Rental { Vehicle = car2, RentalDate = DateTime.Parse("2/2/2010"), Payment = 139.95M }; context.AddToRentals(r1); context.AddToRentals(r2); context.SaveChanges(); } using (var context = new EFRecipesEntities()) { string reportDate = "2/2/2010"; var totalRentals = new ObjectParameter("TotalRentals", typeof(int)); var totalPayments = new ObjectParameter("TotalPayments", typeof(decimal)); var vehicles = context.GetVehiclesWithRentals(DateTime.Parse(reportDate), totalRentals, totalPayments); Console.WriteLine("Rental Activity for {0}",reportDate); Console.WriteLine("Vehicles Rented"); foreach(var vehicle in vehicles) { Console.WriteLine("{0} {1} {2}",vehicle.Year.ToString(), vehicle.Manufacturer, vehicle.Model); } 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-6: Rental Activity for 2/2/2010 Vehicles Rented 2010 Toyota Camry 2010 Chevrolet Corvette
Painting Matrix In Java
Using Barcode printer for Java Control to generate, create Matrix Barcode image in Java applications.
www.OnBarcode.com
Code 128 Code Set B Maker In .NET
Using Barcode encoder for Reporting Service Control to generate, create Code 128 Code Set C image in Reporting Service applications.
www.OnBarcode.com
STORED PROCEDURES
Printing UCC.EAN - 128 In Objective-C
Using Barcode generator for iPhone Control to generate, create UCC-128 image in iPhone applications.
www.OnBarcode.com
Printing EAN128 In Visual C#
Using Barcode creator for .NET framework Control to generate, create GS1 128 image in VS .NET applications.
www.OnBarcode.com
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 printing 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 in Figure 10-4.
Copyright © OnBarcode.com . All rights reserved.