0

I am working on a sample program using EF. I ran the program without first making sure my SQL Database service was running, and it ran fine. But when I discovered my error, I thought that meant no Database was created and so I could simply re-run the project again and have it create the database in the running instance of SQL Express. But instead I get the invalidOperationError telling me

**The model backing the 'BreakAwayContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).**

I am able to get around this error by applying

Database.SetInitializer(
new DropCreateDatabaseIfModelChanges<BreakAwayContext>());

but I still can't find my database.

In the config file, for defaultConnectionFactory, the setting is

<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>

So, I expect the database to be created on the installed instance of SQL 2012 on the machine, but I cannot find the database.

How do I re-set my project so it creates a new database please? Thanks in advance.

4

1 に答える 1

0

たぶんあなたのデータベースはユーザーインスタンスとして作成されていますか?このような場合、ManagementStudioを使用するSQLEXPRESSのデフォルトインスタンスには表示されません。接続文字列で確認できます。ユーザーインスタンスパラメータがあります。trueに設定されている場合は、アプリディレクトリのどこかで.mdfファイルを見つけることができるはずです。

于 2012-12-13T19:53:16.503 に答える