部署实体框架code第一个数据库 [英] Deploy Entity Framework Code First Database

查看:92
本文介绍了部署实体框架code第一个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是实体框架(4.3.1)code首先数据库中的ASP.NET MVC 3应用程序。现在我想创建一个包含数据库,通过Visual Studio 2010和脚本的一切部署到具有IIS7在Windows 2008 Server和SQL Server 2008以prepared(生成的应用程序包一个COM prehensive zip文件但空的)数据库中。

I have an ASP.NET MVC 3 application using an Entity Framework (4.3.1) Code First database. Now I would like to create a comprehensive zip file containing the database, the application package generated by Visual Studio 2010 and a script to deploy everything to a Windows 2008 server with IIS7 and SQL Server 2008 with a prepared (but empty) database.

我不预见与应用程序包的部署任何问题,但我不能确定的是什么方法部署数据库使用。目标环境已经有一个已经分配给我一个空数据库,但我已经告诉删除和创建数据库是好的。

I don't foresee any problems with the deployment of the application package, but I'm unsure of what approach to use in deploying the database. The target environment already has an empty database that's been assigned to me, but I've been told that dropping and creating the database is fine.

从我读过,我可以做.mdf和.ldf文件的直接拷贝到服务器,然后设置我的连接字符串以指向特定的文件,但这种方法排序忽略早已数据库创建(或至少命名)对我来说。另一种方法是使用了现有的.mdf与脚本在服务器上创建的数据库。我在这里的唯一的问题是,我想保留分配给我的数据库名称。

From what I've read, I can do a straightforward copy of the .mdf and .ldf files to the server and then setup my connection string to point to that specific file but this approach sort of ignores the database that has already been created (or at least named) for me. The other approach would be to use the the existing .mdf to create the database on the server with a script. My only issue here is that I would like to keep the database name assigned to me.

推荐答案

我通常连接到本地使用SQL Management Studio,然后右键单击该数据库,选择任务我开发数据库 - >生成脚本。然后,我选择整个数据库或仅仅是表我想继续,点击下一步,然后单击高级按钮,并确保我脚本去模式和数据,然后生成,我可以运行SQL脚本因此生产数据库,保持表结构,那是在开发数据库中的数据。显然,如果你不希望只保留数据,则只需编写脚本的架构。然后,将您的应用程序的连接字符串到新的生产环境中的数据库,你是好去。

I usually connect to my development database locally using SQL Management Studio and right-click the database, choose Tasks -> Generate Scripts. Then I select the entire database or just the tables I'd like to keep, click next, then click the Advanced button and make sure that I am scripting out "Schema and Data", and then generate a sql script that I can run on the production database, therefore keeping the table structure and the data that was in the dev database. Obviously, if you don't want to keep the data then just script out the Schema only. Then, point your application's connection string to the new production environment database and you're good to go.

这篇关于部署实体框架code第一个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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