I'm using the Entity Framework (EF) to create a complex type from a stored procedure. Recently, the stored procedure changed (more return values were added. I would like to update the complex type that maps to this stored procedure. Is this possible and if so, how? I am currently deleting my function import and complex type each time a stored procedure changes, which is most likely not the best approach.
Asked
Active
Viewed 2.8k times
2 Answers
129
I found another way of doing this without deleting the complex type. You can update your Complex Type and Visual Studio will add any changed columns. Here's how:
- Open your .edmx file and go to the model browser.
- If your stored proc changed, right-click on any white area in the model browser and select Update Model From Database, click "Finish". This will refresh your stored procedure.
- Now drill down into XModel.edmx > XModel > EntityContainer:XEntities > Function Imports (X is your entity name) and right-click the one that you need to update. Select Edit.
- Click "Get Column Information". Now, next to the Complex Type radio button, there is a Update button. Press this to update your complex type and then press the OK button.
That should do it!

Rocker2000
- 30
- 6

Halcyon
- 14,631
- 17
- 68
- 99
-
I found 'Function Imports' in the following place: 'Foo.edmx/Foo/EntityContainer: FooEntities/Function Imports' – Matt Stephenson Mar 13 '13 at 18:20
-
9So intuitive! Why didn't I think of that?!?! +1 for your VS exploratory clicking skills, Halcyon. Many thanks. – Paul Prewett Sep 12 '13 at 13:46
-
2It's not necessary to click "Get column information", clicking "Update" alone will do the same thing. – SlimShaggy Feb 24 '14 at 10:47
-
I found "Function Imports" directly one directly higher than Halcyon says. Example: XModel.edmx > XModel > Function Imports (using EF 6.0) – Nate Anderson Jan 28 '15 at 18:13
-
My "Get column information" button was greyed out until I saved a new connection string, but then it worked as stated above. – laylarenee Mar 02 '15 at 14:47
-
Make sure you are not in debug. – Mark Dornian Apr 28 '15 at 20:01
-
3how can you this one by one for large number of function imports? Is there any method to do it at once for all of the function imports? – Lali Jun 12 '15 at 13:31
-
4This is ridiculous that VS doesn't handle this automatically. – LarryBud Dec 01 '16 at 01:50
-
unfortunately this is the only way to update the complex type :( – Ibrahim ben Salah Sep 26 '17 at 08:39
-
Thank you @Halcyon! Agree with all the others about how non-intuitive MS and VS make this. – kenswdev Mar 16 '20 at 16:08
0
There is an easier way to achieve that, look here at SO. It adds some meta information to the stored procedure, which the EF uses to generate the appropriate return type for you.
The meta information part of the stored procedure is not executed, it just tells about which columns and datatypes it returns.