简体   繁体   English

如何更新Entity Framework自动生成的代码以获取存储过程的结果

[英]How to update the Entity Framework auto-generated code for the results of a stored procedure

What I am trying to achieve is to get the auto-generated code to update for the results of a stored procedure. 我想要实现的是获取自动生成的代码以更新存储过程的结果。

What I have done so far is: 到目前为止我所做的是:

  1. Modified the stored procedures in my development database 修改了我的开发数据库中的存储过程
  2. In Visual Studio: 在Visual Studio中:

    2.1 Made sure the connection string is set in the Server Explorer 2.1确保在服务器资源管理器中设置了连接字符串

    2.2 Right clicked on the EDMX diagram and selected Update Model from database. 2.2右键单击EDMX图并从数据库中选择更新模型。 The update wizard is displayed. 将显示更新向导。 I don't add anything, and I check the stored procedure is in the list. 我没有添加任何内容,我检查存储过程是否在列表中。 After this I click the Finish button. 在此之后,我单击完成按钮。

  3. I then get the "Running this text template can potentially harm your computer" message twice, which I click OK on. 然后我得到“运行此文本模板可能会损害您的计算机”消息两次,我单击确定。

  4. Save the changes 保存更改

  5. Build the DLL 构建DLL

  6. Right click on the tt (not the context one) under the EDMX and select run custom tool. 右键单击EDMX下的tt(不是上下文一个)并选择运行自定义工具。 I get the same security message as above, so click ok. 我得到与上面相同的安全消息,所以单击确定。

Everything seems to be running ok, and there are no obvious errors. 一切似乎都运行正常,没有明显的错误。

I have also tried the Transform All T4 Templates under the build menu. 我还尝试了构建菜单下的Transform All T4 Templates。

I am using Visual Studio 2013 with SQL Server 2014. The Entity Framework runtime version is 4.0.30319. 我使用Visual Studio 2013与SQL Server 2014.实体框架运行时版本是4.0.30319。

I have had a look in the EDMX xml file and there is an entry for the FunctionImportMapping for the stored procedure and the class it will create. 我查看了EDMX xml文件,并且存在一个用于存储过程的FunctionImportMapping条目以及它将创建的类。

If it makes any difference when I try to connect to the database using the SQL Server Object Explorer in Visual Studio, it displays the SQL Server 2012 login, if I click connect it displays the "An incompatible SQL Server version was detected". 如果在尝试使用Visual Studio中的SQL Server对象资源管理器连接到数据库时有任何不同,它会显示SQL Server 2012登录,如果单击“连接”,则会显示“检测到不兼容的SQL Server版本”。 That can be cured by installing the latest version of SSDT for Visual Studio 2013. 可以通过为Visual Studio 2013安装最新版本的SSDT来解决这个问题。

I am new to Entity Framework, so any help will be appreciated. 我是Entity Framework的新手,所以任何帮助都将不胜感激。

How do I get the class to update, or is it that I am overthinking the issue and have to update it manually? 如何让课程更新,或者我是否在思考问题并且必须手动更新?

Thank you for your help. 谢谢您的帮助。

I have found a solution which seems to have done the trick: 我找到了一个解决方案似乎已经完成了这个诀窍:

  1. Open the EDMX diagram 打开EDMX图表
  2. Update the model from the database 从数据库更新模型
  3. Right click on the diagram and select Model Browser from the menu 右键单击图表,然后从菜单中选择Model Browser
  4. Expand the Function Imports folder 展开Function Imports文件夹
  5. Find the stored procedure that has been modified. 找到已修改的存储过程。
  6. Double click on it and the Edit Function Import form will be displayed 双击它,将显示编辑功能导入表单
  7. Click Get Column Information 单击获取列信息
  8. Ensure the correct complex type is selected, and click update. 确保选择了正确的复杂类型,然后单击“更新”。
  9. Click OK 单击确定

The new columns should now be added to the auto-generated code. 现在应将新列添加到自动生成的代码中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM