Command Text With Scalar Result

This topic describes how to create a method, which will execute a parameterized query returning a scalar result - the number of table records that satisfy the query condition, in Entity Developer Entity Framework model.

For this, perform the following steps:

1.In the Model Explorer window right-click the Stored Procedures node, select the Add submenu and then select New Command Text.
2.In the Command Text Editor dialog specify the stored procedure name and the SQL script:

images_command-text-scalar-general-EF

3.Customize the parameters:

images_command-text-scalar-params-EF

4.Click OK.
5.Right-click the created stored procedure and select Create Method in the context menu.
6.In the Method Editor dialog box specify the required Return Type:

images_command-text-scalar-method-general-EF

7.Customize the parameters:

images_command-text-scalar-method-params-EF

8.Click OK.

The method is created.

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 global::System.Nullable<int> GetNumberOfDepartmentsByLocation (string Loc)

 

Visual Basic:

Public Function GetNumberOfDepartmentsByLocation (ByVal Loc As String) As Global.System.Nullable(Of Integer)

 

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

 

ExpandedToggleIcon        See Also


Send feedback on this topic

© 2008 - 2024 Devart. All rights reserved.