我依旧记得看过帖子但又找不到了 - 我正在使用EF4 CTP5 Code-First。
I vaguely remember seeing a post but can't find it anymore -- I'm using EF4 CTP5 Code-First.
在我创建数据库后的DbContext中,我还想执行一些SQL脚本。这些包含我的存储过程,用户函数和设置数据。
In my DbContext after I create the database, I want to also execute a number of SQL scripts. These contain my stored procedures, user functions, and setup data.
显然,对于生产,我们有自己的构建脚本可以自动完成所有这些,但我希望个人开发人员将用于从源代码控制中提取最新信息并点击F5 ...有关如何执行此操作的任何建议吗?
Obviously, for production, we'd have our own build scripts that will automate all of this, but I want individual developers who will be use to pulling down the latest from source control and hitting F5... any recommendations on how to do this?
或者,我应该只是对硬件进行"硬编码"并明确地?例如。
Or, should I just 'hard-code' the logic and explicitly? e.g.
context.Database.SqlCommand(" exec myPath\myscript.sql")???这样的事情?
context.Database.SqlCommand("exec myPath\myscript.sql" )??? something like this?
即。类似于ADO.Net的Command.ExecuteNonQuery?代码示例将不胜感激。
i.e. something similar to ADO.Net's Command.ExecuteNonQuery? Code sample would be appreciated.
谢谢
Ray
推荐答案
Hi Ray,
Hi Ray,
这篇文章显示了我们建议的方法; romiller/2010/07/31/ef-ctp4-tips-tricks-running -additional-ddl /
This post shows our suggested approach;romiller/2010/07/31/ef-ctp4-tips-tricks-running-additional-ddl/
帖子使用CTP4 API表面,在CTP5中有几个重命名:
The post uses the CTP4 API surface and there have been a couple of renames in CTP5:
- 数据库=> System.Data.Entity.Database.DbDatabase
- RecreateDatabaseIfModelChanges => System.Data.Entity.Database.DropCreateDatabaseIfModelChanges
- AlwaysRecreateDatabase => System.Data.Entity.Database.DropCreateDatabaseAlways
- CreateDatabaseIfNotExists => System.Data.Entity.Database.CreateDatabaseIfNotExists
更多推荐
为安装数据创建数据库+执行SQL脚本?
发布评论