为安装数据创建数据库+执行SQL脚本?

编程入门 行业动态 更新时间:2024-10-14 12:25:34
本文介绍了为安装数据创建数据库+执行SQL脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我依旧记得看过帖子但又找不到了 - 我正在使用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
~Rowan

更多推荐

为安装数据创建数据库+执行SQL脚本?

本文发布于:2023-07-15 13:02:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1111381.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   数据库   数据   SQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!