Adding stored procedures complex types in Entity Framework

OK – here’s the step-by-step way of doing this:

(1) add your stored procedure to the EDMX file (when you first create it, or later on by using Update model from database and picking that stored procedure)

(2) once you have the stored procedure in your model – use the Model Browser to add a Function Import :

enter image description here

(3) the next dialog that pops up is vitally important – you need to (1) define that the stored procedure returns a collection of complex types, then you need to (2) get the column info from that stored procedure to know what columns it will return, then (3) you tell Visual Studio to generate a new complex type based on that column info:

enter image description here

(4) once you’ve done that – you should now see the stored procedure in your conceptual model section in the Model Browser, and the newly generated complex type should show up there, too:

enter image description here

Leave a Comment