Manually added stored procedures in edmx file

偶尔善良 提交于 2019-12-01 06:10:48

Moo, you should not modify the edmx file by hand.

"Changes to this file may cause incorrect behavior and will be lost if the code is regenerated."

That´s why you´re losing your work. You should map the already created stored procedure from the designer, the same way you made with your tables.

I´m assuming you´re playing with EF4.

Termato

This solution works if you did Model First and don't want to generate the model from the database. (Using VS2013, EF6, MVC5)

Open your EDMX file. Right Click and press Update Model from Database. Only check "Stored Procedures and FUnctions" and uncheck the two boxes at the bottom except "Import Selected Stored Procedures and functions into the entity model" (see image below)

Note: If you have data annotations, etc., they will be regenerated and overwritten.

Reference: Using stored procedures in Entity Framework Model First Approach (Part I - Adding New Stored procedure)


Further Explanation and Detail:

"When the Entity Data Model Wizard generates an .edmx file from a database, it creates entries in the storage model for each stored procedure in the database. Corresponding entries are added to the conceptual model when function imports are created." How to: Import a Stored Procedure (Entity Data Model Tools)

It appears you have to update your model from the database in order to use the "Add New > Function Import.." wizard to import a stored procedures. Otherwise, it wont show up on the list. If you add them manually, you do run the risk of them being overwritten. This will happen every time you edit your model. You'd have to keep that code up to date anytime you made changes to the model or database (I'd keep a back up copy of it).

Here is how you do it by generating the model from the database: EF Model First with Stored Procedures

They also reference updating the model from database in this MSDN Community Support Forum: how to add new stored procedure to existing .edmx file

This is the only way I've found to update the stored procedures WITHOUT updating the model.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!