Stored Procedure with Output Parameters

This example shows how to use a stored procedure with output parameters.

The script for creating a stored procedure for the SQL Server DBMS is as follows:

CREATE PROCEDURE dbo.SinAndCos(@angle float,@sin float OUTPUT, @cos float OUTPUT)
AS
SET @sin=SIN(@angle)
SET @cos=COS(@angle)
GO

First, we create a model and drag the corresponding stored procedure from the Database Explorer window to the diagram area.

As a result, we will get a method in the model corresponding to the stored procedure:

images_SP-with-out-params-General-EF

With the following parameters:

images_SP-with-out-params-params-EF

As a result of code generation for the model, the corresponding method of the model context will be generated having a signature close to the relevant stored procedure:

C#:

public void SinAndCos (global::System.Nullable<double> angle, ref global::System.Nullable<double> sin, ref global::System.Nullable<double> cos)

Visual Basic:

Public Sub SinAndCos (ByVal angle As Global.System.Nullable(Of Double), ByRef sin As Global.System.Nullable(Of Double), ByRef cos As Global.System.Nullable(Of Double))

Now it is possible to use this stored procedure in the application with the help of method wrapper. This allows working with the stored procedure with all possible convenience, as wrapper methods are strongly typed, are found by IntelliSense and have signatures close to the corresponding stored procedures.

ExpandedToggleIcon        See Also


Send feedback on this topic

© 2008 - 2024 Devart. All rights reserved.