存储过程和更新 EDMX

我在存储过程和 EDMX 方面遇到了无穷无尽的问题。我创建了一个过程,从数据库中更新了模型,所有的工作都完成了。然后,我删除了一个列,并在存储过程中添加了一个新列。我更新了模型,但是 EDMX 似乎没有更新过程定义。

我删除了 proc,并进行了更新,但必须手动删除对 proc 的所有引用。最后,我只是重命名了 proc,并通过模型更新从数据库导入。

我也有同样的问题。添加了一个新列,并重命名了一个现有列。我通过数据库中的更新模型刷新了 EDMX,但是没有对 EDMX 进行任何更改,而且显然在运行时会失败。存储过程更新应该如何使用实体框架完成?

enter image description here

我删除了 proc,重新生成了模型,删除了 proc 的“ cs”文件,编译,然后再次将过程添加到数据库中,重新生成了模型,砰!它将相同的模型添加3次,只有最后一次是正确的。为什么它总是把旧版本带回来?

79246 次浏览

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.

(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.

  1. 1st place- Under Complex Types-> as MyStoreProc_result
  2. 2nd Place- Under Function Imports -> as MyStoreProc
  3. 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 :)

First of all do refresh your SP through "Update Model from Database", if it is working, fine, if not and throwing the same exception then do follow the steps given below. 1.Double Click on .edmx file. 2. In Model Browser, Delete SP from Complex Types, Function Imports and Stored Procedures/Functions. 3. Save All. 4.Add again your SP through "Update Model from Database". 5.Save All.

To refresh an existing stored procedure in edmx file,

  1. Go to "Model Browser" > "Function Imports" > find the desired stored procedure class > right click and click on "Edit"
  2. In "Edit Function Import" form, in "Returns a Collection Of" section, click on "Update" button
  3. Click "OK" to finish the refresh.

enter image description here

Follow these steps:

Step 1: Open Edmx

enter image description here

Step 2: Open Model Browser

enter image description here

Step 3: Open Complex Types and remove your procedure_Result

enter image description here

Step 4: Open Functions Imports and delete your procedure

enter image description here

Step 5 Open StoredProcedur and Functions and delete your procedure

enter image description here

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 !

(Tested for EF6 in Visual Studio Community 2019 v16.8.5)

Go to Model browser and browse to your procedure. Either of the following two places:

  1. Model > Function Imports > myProcedure
  2. Store > Stored Procedures / Functions > myProcedure

(If you are still not sure how to browse to your procedure, follow illustrations/images in Ishwor Khanal's post.)

Right click on your procedure, select "Update Model from Database..." from context menu.
Context Menu

Click on "Refresh" tab

enter image description here

Open "Stored Procedures and Functions" and then "dbo".

Select the Stored Procedure you want to update and then click "Finish". enter image description here

Done! (Lesser hassle than deleting and then importing again ;-) )

I'd been experiencing the same issue with a SP I was updating. I tried all the solutions suggested here and nothing worked (in fact, the SP had no result columns after the update)

Then I remembered when an SP uses temporal tables it has a weird behaviour.

That's why I added on SQL this line:

SET FMTONLY OFF;

With it, I could update the SP in Visual Studio (used Fábio's solution)

Hope this help anyone who experiences this same problem