EF 6数据库第一:如何更新存储过程? [英] EF 6 database first: How to update stored procedures?

本文介绍了EF 6数据库第一:如何更新存储过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用实体框架6.0.0 ,并首先使用数据库(如此)从表和存储过程生成代码。这似乎很好,除了在更新或刷新模型时没有反映存储过程的更改。向列中添加列反映出来,但不会向存储过程添加一个字段。



有趣的是,如果我去模型浏览器,右键单击存储过程,选择添加功能导入,然后点击按钮获取列信息,我们可以看到正确的列。这意味着模型知道列,但不能更新生成的代码。



有一种解决方法,那就是在更新模型之前删除生成的存储过程。只要您没有对存储过程进行任何编辑,此操作就可以工作。有没有人知道避免这种解决方法的方法?



我正在使用 Visual Studio 2013 与所有最新的更新截至2013年12月初。



提前感谢!



更新1:
andersr的答案有助于一种情况,存储过程使用临时表,所以我给他+1,但它仍然不能解决更新简单存储过程的主要问题。



更新2:
shimron的评论以下链接到有关EF 3.5中相同问题的问题。对于EF 6.0来说似乎也是如此。阅读它的另一种方法,但现在我的结论是,最简单的方法是在更新模型之前删除生成的存储过程。

解决方案

根据这个答案 DaveD ,这些步骤解决了这个问题:


  1. 在您的 .edmx 中,rt单击并选择模型浏览器

  2. 在模型浏览器中(在VS 2015默认配置中,它是解决方案资源管理器中的一个选项卡),展开模型下的功能导入。 li>
  3. 双击您的存储过程。

  4. 点击返回一个集合 - 复合(如果没有返回标量或实体)

  5. 点击好的,然后点击保存您的.edmx,以反映您的$ / $>

    We are using Entity Framework 6.0.0 and use database first (like this) to generate code from tables and stored procedures. This seems to work great, except that changes in stored procedures are not reflected when updating or refreshing the model. Adding a column to a table is reflected, but not adding a field to a stored procedure.

    It is interesting that if I go to the Model Browser, right click the stored procedure, select Add Function Import and click the button Get Column Information we can see the correct columns. This means that the model knows of the columns, but does not manage to update the generated code.

    There is one workaround, and that is to delete the generated stored procedure before updating the model. This works as long as you have not made any edits on the stored procedure. Does anyone know of a way to avoid this workaround?

    I am using Visual Studio 2013 with all the latest updates as of early December 2013.

    Thanks in advance!

    Update 1: andersr's answer helped in one case, where the stored procedure used a temporary table, so i gave him +1, but it still does not solve the main problem of updating simple stored procedures.

    Update 2: shimron's comment below links to a question about the same issues in EF 3.5. It seems the same is still true for EF 6.0. Read it for an alternative way of doing it, but my conclusion as of now is that the simplest way of doing it is to delete the generated stored procedure before updating the model. Use partial classes if you want to do something fancy.

    解决方案

    Based on this answer by DaveD, these steps address the issue:

    1. In your .edmx, rt-click and select Model Browser.
    2. Within the Model Browser (in VS 2015 default configuration, it is a tab within the Solution Explorer), expand Function Imports under the model.
    3. Double-click your stored procedure.
    4. Click the Update button next to Returns a Collection Of - Complex (if not returning a scalar or entity)
    5. Click okay then save your .edmx to reflect field changes to your stored procedure throughout your project.

    这篇关于EF 6数据库第一:如何更新存储过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆