Command Text With Resultset

This topic describes how to create a method, which will execute a parameterized query returning the table records that satisfy the query condition as the list of corresponding entity objects, in Entity Developer Entity Framework model.

For this, perform the following steps:

1.This example requires adding either the Department entity, or a complex type; we use the entity in this example. It can be created either manually, or dropped on the design area from the Database Explorer window.
2.In the Model Explorer window right-click the Stored Procedures node, select the Add submenu and then select New Command Text.
3.In the Command Text Editor dialog specify the stored procedure name and the SQL script:

images_command-text-resultset-general-EF

4.Customize the parameters:

images_command-text-resultset-params-EF

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

images_command-text-resultset-method-general-EF

8.Customize the parameters:

images_command-text-resultset-method-params-EF

9.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 ObjectResult<department> GetDepartmentsByLocation (string Loc)

 

Visual Basic:

Public Function GetDepartmentsByLocation (ByVal Loc As String) As ObjectResult(Of Department)

 

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.