EF 6 database first: How to update stored procedures?

ef-database-first entity-framework entity-framework-6 stored-procedures visual-studio-2013


To produce code from tables and stored procedures, we are utilizing 6.0.0 Entity Framework and database first (As in this). This appears to operate perfectly, but when updating or refreshing the model, changes in saved processes are not reflected. A table's addition of a column is reflected, while a stored procedure's addition of a field is not.

It's intriguing to see that if I visit theModel Browser pick the saved procedure by right-clicking it.Add Function Import then press the buttonGet Column Information The correct columns are shown. This indicates that although the model of the columns is knows, it is unable to alter the generated code.

The generated stored procedure can be removed as a workaround by doing so before upgrading the model. As long as you haven't changed the stored procedure in any way, this will work. Does anyone know how to go around this solution?

I utilizeVisual Studio 2013 with the most recent updates as of the first week of December 2013.

I appreciate it.

1. Update: I gave andersr a plus one because his response was helpful in one scenario where a temporary table was utilized by a stored procedure, but it still does not address the fundamental issue of updating simple stored procedures.

The remark below from 2. Update: shimron contains a link to a query on the similar problems in EF 3.5. For EF 6.0, it appears that the same is still valid. You can read it for an alternative method, but as of right now, I've come to the conclusion that deleting the produced stored procedure before updating the model is the simplest method. If you want to do something sophisticated, use partial classes.

1/2/2014 8:53:12 AM

Accepted Answer

Using this response by DaveD, the following procedures take care of the problem:

  1. As you.edmx and then rt-click on Type of browser.
  2. Expand Feature Imports beneath the model in the Model Browser (by default, it is a tab in the Solution Explorer in Visual Studio 2015).
  3. Click on your stored procedure twice.
  4. Next to gives back a collection of complex objects., select the Update button (if not returning a scalar or entity)
  5. To reflect field changes to your stored procedure throughout your project, click okay then save your.edmx.
5/23/2017 12:26:05 PM

Popular Answer

Do your stored procedures, by chance, return data from temporary tables? This does not appear to be supported by EF; for further details, see EF4 - No columns are returned by the specified stored procedure.

However, as you noticed, the stored procedure will be accessible in the Model Browser. I conducted a little test using the circumstances mentioned above. My context class generated the stored procedure, however it had an int return type instead of a complex type.. See the aforementioned website for possible workarounds.

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow