How to: Execute a Parameterized Stored Procedure Using EntityCommand

 

This topic shows how to execute a parameterized stored procedure by using the EntityCommand class.

To run the code in this example

  1. Add the School Model to your project and configure your project to use the Entity Framework. For more information, see How to: Use the Entity Data Model Wizard.

  2. In the code page for your application, add the following using statements (Imports in Visual Basic):

    [!CODE [DP EntityServices Concepts#Namespaces](../CodeSnippet/VS_Snippets_Data/dp entityservices concepts#namespaces)]

  3. Import the GetStudentGrades stored procedure and specify CourseGrade entities as a return type. For information on how to import a stored procedure, see How to: Import a Stored Procedure.

The following code executes the GetStudentGrades stored procedure where StudentId is a required parameter. The results are then read by an EntityDataReader.

[!CODE [DP EntityServices Concepts#StoredProcWithEntityCommand](../CodeSnippet/VS_Snippets_Data/dp entityservices concepts#storedprocwithentitycommand)]

EntityClient Provider for the Entity Framework

Show: