EF模型先用存储过程 [英] EF Model First with Stored Procedures

查看:131
本文介绍了EF模型先用存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用EF 4模型一...我生成的模型数据库。 我将如何能够使用在该方案中存储,程序?它们也应与该数据库自动生成..?

I'm using EF 4 with model-first...I generate the database from the model. How would I be able to use stored-procedures in that scenario? They should also be auto-generated with the database..?

推荐答案

您不必与模型的任何存储过程第一,不会产生。他们怎么可能呢?在数据库中存储过程的逻辑定义和EF没有知识的过程,因此它不能创建它们的。

You don't have any stored procedures with model first and there will not be generated. How could they be? Stored procedure is logic defined in the database and EF has no knowledge of that procedure so it cannot create them for you.

如果你想使用存储过程的第一个创建模型和交换你的数据库的数据库。然后,您可以手动定义你的程序,并将它们映射到模型。一旦你这样做,你不能回去模型第一。

If you want to use stored procedures create your database from model and swap to database first. Then you can manually define your procedures and map them to the model. Once you do that you cannot go back to the model first.

编辑:

有可能是多了一个解决方案,但它是不是很好。你将保持自定义的SQL脚本,以使用所有的存储过程(你必须这么写他们),你将修改工作流程数据库创建运行脚本创建数据库之后。模型首先使用T4模板来生成SQL和工作流程的基础4来处理数据库创建的全过程。无论T4模板和工作流程可定制。的问题是,这一步骤将增加存储你的程序,但它不会将它们映射在EDMX

There is probably one more solution but it is not nice. You will maintain custom SQL script to with all your stored procedures (you will have to write them anyway) and you will modify workflow for database creation to run your script after database is created. Model first uses T4 templates to generate SQL and Workflow foundation 4 to handle whole process of database creation. Both T4 template and workflow can be customized. The problem is that this step will add stored procedures for you but it will not map them in EDMX.

这篇关于EF模型先用存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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