C# 存储过程和更新 EDMX
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18038405/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Stored Procedures and updating EDMX
提问by Craig
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.
我在存储过程和 EDMX 方面遇到了无穷无尽的问题。我创建了一个程序,从数据库更新了模型,一切正常。然后我删除了一列并在存储过程中添加了一个新列。我更新了模型,但 EDMX 似乎没有刷新 proc 定义。
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.
我删除了 proc,并进行了更新,但必须手动删除对 proc 的所有引用。我最终只是重命名了 proc 并通过模型更新从数据库导入。
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?
我只是有同样的问题。添加了一个新列,并重命名了一个现有列。我通过数据库中的更新模型刷新了 EDMX,但 EDMX 没有更改,显然在运行时,它失败了。如何使用实体框架完成存储过程更新?
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?
我删除了 proc,重新生成了模型,删除了 proc 的“cs”文件,编译,然后再次将程序添加到数据库中,重新生成了模型,然后砰!它添加了 3 次相同的模型,只有最后一个是正确的。为什么它不断带回旧版本?
采纳答案by SArifin
(This solution is for EF 6. I have not tried in other EF versions. It works nice.)
(此解决方案适用于 EF 6。我还没有在其他 EF 版本中尝试过。效果很好。)
Go to Model browser. MyStoreProc is the name of the stored procedure (as an example). MyStoreProc will appear in 3 places.
转到模型浏览器。MyStoreProc 是存储过程的名称(作为示例)。MyStoreProc 将出现在 3 个地方。
- 1st place- Under Complex Types-> as MyStoreProc_result
- 2nd Place- Under Function Imports -> as MyStoreProc
- 3rd Place - Under Stored Procdures/ Functions -> as MyStoreProc
- 第 1 名 - 在复杂类型下 -> 作为 MyStoreProc_result
- 第二名 - 在函数导入下 -> 作为 MyStoreProc
- 第三名 - 在存储过程/函数下 -> 作为 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.
从模型中删除所有三个。保存 edmx(通过单击窗口然后 ctrl+S)。然后右键单击并单击从数据库更新模型。然后添加更新的存储过程并再次保存。
Solved without any hassle :)
解决没有任何麻烦:)
回答by Craig
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.
我能找到的唯一解决方法是关闭 EDMX,然后手动编辑 XML,即使在从数据库中删除存储的 proc 并从数据库更新模型之后,仍然提到了 proc。从 XML 中删除这些行已经解决了这个问题。
回答by MS Wani
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.
首先,请通过“从数据库更新模型”刷新您的 SP,如果它工作正常,则很好,如果没有并抛出相同的异常,请按照下面给出的步骤操作。1.双击 .edmx 文件。2. 在模型浏览器中,从复杂类型、函数导入和存储过程/函数中删除 SP。3. 全部保存。4.通过“从数据库更新模型”再次添加您的SP。5.全部保存。
回答by Fábio Nascimento
To refresh an existing stored procedure in edmx file,
要刷新 edmx 文件中的现有存储过程,
- 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.
- 转到“模型浏览器”>“函数导入”>找到所需的存储过程类>右键单击并单击“编辑”
- 在“编辑函数导入”表单中,在“返回集合”部分中,单击“更新”按钮
- 单击“确定”完成刷新。
回答by Ishwor Khanal
Follow these steps:
按着这些次序:
Step 1: Open Edmx
第 1 步:打开 Edmx
Step 2: Open Model Browser
步骤 2:打开模型浏览器
Step 3: Open Complex Types and remvoe your procedure_Result
第 3 步:打开复杂类型并删除您的 procedure_Result
Step 4: Open Functions Imports and delete your procedure
第 4 步:打开 Functions Imports 并删除您的 procedure
Step 5 Open StoredProcedur and Functions and delete your procedure
步骤 5 打开 StoredProcedur 和 Functions 并删除您的 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 !
第 6 步:保存 Edmx(Ctrl+S), Clean Solution , Update Model From Database
并选择您procedure
想要更新的最终clean, build
解决方案。完毕 !