如何运行对一个MDF文件的SQL脚本?脚本、文件、MDF、SQL

2023-09-04 09:18:59 作者:暖心人

我已经创建了使用Entity Framework的4.0模式,第一种方法数据库模型。然后,我使用的生成数据库从型号... 的我也已经在我的App_Data文件夹中创建一个SQL Server数据库文件中创建一个SQL脚本。我怎么现在跑反对这个MDF文件的SQL文件?

I've created a database model with model-first method using Entity Framework 4.0. I then created an sql script using the Generate Database from Model... I've also created an SQL Server Database file in my App_Data folder. How do I now run the SQL file against this MDF file?

我在使用Visual Studio 2010。

I'm using Visual Studio 2010.

推荐答案

我找到了解决办法,但它是一个有点哈克。

I found a solution, but it's a bit hacky.

我的SQL Server防爆preSS(2008 R2)。因此,从模型生成数据库,当我连接到它,让它建立数据库出现。然后我去 C:\ Program Files文件\ Microsoft SQL Server的\ MSSQL10_50.SQLEX $ P $干燥综合征\ MSSQL \ DATA 。在10_50部分是因为该版本可以为你不同。因此,此文件夹中有一个名为就像数据库.mdf文件 - .MDF。还有一个_log.ldf文件。我复制到这些到我的项目的App_Data文件夹。

I have SQL Server Express (2008 R2). So when generating the database from the model I connect to it and let it build a database there. Then I go to C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA. The 10_50 part is because of the version and can be different for you. So in this folder there's a .mdf file named just like the database - .mdf. There's also a _log.ldf file. I copied these to into the App_Data folder of my project.

这工作,但会消耗来生成一个新的.mdf数据库模型中的每一个变化很花时间。所以,我这样做只是在装运前。

This works but is very time consuming to generate a new .mdf database for every change in the model. So I do this just before shipping.

如果你找到一个更好的答案请你分享。

If you find a better answer please do share.