Export (0) Print
Expand All

How to: Import a Stored Procedure

[This page is specific to the latest version of the Entity Framework. The latest version is available as the 'Entity Framework' NuGet package. For more information, see Entity Framework Releases and Versioning.]

This topic describes how to use the Entity Designer to import a stored procedure.

When a stored procedure is added to a conceptual model, it is called a function import . Adding a function import allows you to call the corresponding stored procedure from your application code. A function import can return collections of simple types, EntityTypes , or ComplexTypes , or no value.

The insert, update, and delete operations of an entity type can be mapped to stored procedures. For more information, see How to: Map Modification Functions to Stored Procedures.

When the Entity Data Model Wizard generates an .edmx file from a database, it creates entries in the storage model for each stored procedure in the database. Corresponding entries are added to the conceptual model when function imports are created.

The procedure below describes how to create a function import. For information about calling a function import from application code, see How to Execute a Query Using a Stored Procedure.

To create a function import

  1. Do one of the following from the Model Browser :

    • Open the Stored Procedures folder (in the storage model information) and double-click a stored procedure that does not have a corresponding function import.

    - OR -

    • Right-click the Function Imports folder (in the EntityContainer node of the conceptual model information) and then select Add Function Import .

    The Add Function Import dialog box appears.

  2. Fill in the settings for the new function import.

    • Specify the stored procedure for which you are creating a function import in the Stored Procedure Name field. This field is a drop-down list that displays all the stored procedures in the storage model. If the desired stored procedure is not available, you may need to update your storage model. For more information, see How to: Update an .edmx File when the Database Changes.

    • Specify the name of the function import in the Function Import Name field.

    • Specify one of the four basic return types: None , Scalars, Complex , or Entities , and select the specific return type from the available drop-down list. If you choose Complex , the Entity Designer can create a new complex type with properties that correspond to the columns returned by the stored procedure.

    1. Click Get Column Information to retrieve column information.

    2. Click Create New Complex Type .

    3. Edit the name of the complex type in the Complex drop-down list.

      When you click OK , a new complex type is added to the conceptual model and the return type of the function import is set to this new type.

      If you have changed the definition for your stored procedure in the storage model, you can automatically update the complex type it returns by clicking Update .

    Starting with Visual Studio 2012, the dialog that lets you choose the database objects that you want to include in your model, contains the Import selected stored procedures and functions into the entity model check box. Leave it checked if you want for the functions to be automatically imported into the model. When using this option, the result shape of each stored procedure will automatically become a new complex type in your entity model.

    If your application targets the .NET Framework 3.5 SP1, complex types are not supported as a return type for function imports.

  3. Click OK .

Build Date:

© 2015 Microsoft