HV-Lima Peru

Offshore your .NET/SQL Development to Latin America! Languages: en-de-es

Category Archives: Entity Framework

How to call a Stored Procedure through EF4?

In the following it is used the AdventureWorks DB on SQL Server 2008.

Add a new Stored Procedure from the DB to the Entity Framework via Update Model:

In the case I added the following usp:

EF has two parts, the DB-side (where we added the Stored Proc) and the object-side where we will create the needed classes now.
A double click on the new Stored Proc above (or right click, Add Function Import) opens the dialog Add Function Import below.

 

Click the first button (A:) to get the output column info from the SP, then the second button (B:) to create a new complex type, based on this info, then OK

This creates the complex type and C#-Function on the EF4-object-side:

Calling the SP through EF is accomplished like so:
Observe the datatype of the list p

Here comes the result of the first entry of p:

Compare this with the result of calling directly the SP in SSMS: