Stored Procedures and updating EDMX
I have had endless issues with stored procedures and EDMX. I created a procedure, updated the model from the database, and all worked. I then removed a column and added a new one in the stored procedure. I updated the model, but the EDMX didn't seem to refresh the proc definition.
I dropped the proc, and did an update, but manually had to delete all references to the proc. I ended up just renaming the proc and importing via model update from database.
I just had the same issue. Added a new column, and renamed an existing column. I refreshed the EDMX via update model from database, but there were no changes to the EDMX, and obviously at run time, it fails. How should a stored procedure update be done with Entity Framework?
I removed the proc, regenerated the model, deleted the 'cs' files for the proc, compiled, then added the procedure to the database again, regenerated the model, and bang! It adds the same model 3 times, with only the last one being right. Why does it keep bringing back the old versions?
Solution 1:
(This solution is for EF 6. I have not tried in other EF versions. It works nice.)
Go to Model browser. MyStoreProc is the name of the stored procedure (as an example). MyStoreProc will appear in 3 places.
- 1st place- Under Complex Types-> as MyStoreProc_result
- 2nd Place- Under Function Imports -> as MyStoreProc
- 3rd Place - Under Stored Procdures/ Functions -> as MyStoreProc
Delete all three from model. Save the edmx (by clicking in the window then ctrl+S). Then right click and click update the model from database. Then add the updated stored procedure and Save again.
Solved without any hassle :)
Solution 2:
To refresh an existing stored procedure in edmx file,
- Go to "Model Browser" > "Function Imports" > find the desired stored procedure class > right click and click on "Edit"
- In "Edit Function Import" form, in "Returns a Collection Of" section, click on "Update" button
- Click "OK" to finish the refresh.
Solution 3:
Follow these steps:
Step 1: Open Edmx
Step 2: Open Model Browser
Step 3: Open Complex Types and remove your procedure_Result
Step 4: Open Functions Imports and delete your procedure
Step 5 Open StoredProcedur and Functions and delete your procedure
Step 6: Save Edmx (Ctrl+S), Clean Solution , Update Model From Database
and select your procedure
which you would like to get updated then finally clean, build
solution.
Done !
Solution 4:
The only fix I could find was to close the EDMX, and manually edit the XML, which, even after removing the stored proc from the database, and updating the model from the database - still had mention of the proc. Removing the lines from the XML has solved the issue.