0

私は、SQLデータベースでasp.netでAzureを使用するチュートリアルに従っており、受け取ったエラーを乗り越えようとするのに苦労しています。私がフォローしているチュートリアルは、「http://www.windowsazure.com/en-us/develop/net/tutorials/web-site-with-sql-database/#aspnetwindowsazureinfo」です。

パッケージ マネージャー コンソールで、「enable-migrations -ContextTypeName ToDoListApp.Models.ToDoDb」と入力すると、以下の出力に示すように正しく機能しました。

Checking if the context targets an existing database...
Code First Migrations enabled for project ToDoListApp.

次に「add-migration Initial」と入力すると、このエラーが表示されました..

「ターゲット データベースが EF 4.3 より前のバージョンの Code First で作成されており、移行履歴テーブルが含まれていないため、次の移行をスキャフォールディングできません。このデータベースに対して移行の使用を開始するには、現在のモデルがターゲット データベースと互換性があることを確認し、移行の更新プロセスを実行します (Visual Studio では、パッケージ マネージャー コンソールから Update-Database コマンドを使用して、移行の更新プロセスを実行できます)。

コマンド「-Verbose」も使用しました-エラーがターゲットデータベースにあることがわかりました。

Using StartUp project 'ToDoListApp'.
Using NuGet project 'ToDoListApp'.
Target database is: 'ToDoListApp.Models.ToDoDb' (DataSource: .\SQLEXPRESS, Provider: System.Data.SqlClient, Origin: Convention). 
  • 注:* azure で Web サイトをセットアップし、SQL データベースと共に、公開してこのプロジェクトにリンクしました。

Google にエラーを入力しました。「Add-Migration InitialMigration -IgnoreChanges」で修正できると言う人もいます。

「http://www.woohoo.uk.com/Blog/updating-entity-framework-4-1-with-code-first-migrations」

他の人は、パッケージ マネージャー コンソールで update-database だけを実行すると言いますが、どちらも機能していないようです。Microsoft から提供されたチュートリアルに従っていますが、途中でこの問題を受け取りました。

この状況を解決するための助けがあれば、私はVisual Studio 2012、c#asp.net mv3 Framework 4.5を使用しています。

私のweb.configファイルに、コードも入力しました

 <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  <contexts>
      <context type="ToDoListApp.Models.ToDoDb, ToDoListApp">
        <databaseInitializer type="System.Data.Entity.MigrateDatabaseToLatestVersion">
        <parameters>
          <parameter value="ToDoDb_DatabasePublish"/>
        </parameters>
        </databaseInitializer>
      </context>
    </contexts>
  </entityFramework>

「Add-Migration InitialMigration -IgnoreChanges」と入力しました

出力されたエラーは..

 System.InvalidOperationException: Failed to set database initializer of type                 'System.Data.Entity.MigrateDatabaseToLatestVersion' for DbContext type 'ToDoListApp.Models.ToDoDb, ToDoListApp' specified in the application configuration. See inner exception for details. ---> System.TypeLoadException: Could not load type 'System.Data.Entity.MigrateDatabaseToLatestVersion' from assembly 'EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
   at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type)
   at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName)
   at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase,  Boolean reflectionOnly, StackCrawlMark& stackMark)
   at System.Type.GetType(String typeName, Boolean throwOnError)
   at System.Data.Entity.Internal.ConfigFile.DatabaseInitializerElement.GetInitializerType()
   at System.Data.Entity.Internal.AppConfig.InternalApplyInitializers(Boolean force)
   --- End of inner exception stack trace ---
   at System.Data.Entity.Internal.AppConfig.InternalApplyInitializers(Boolean force)
   at System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
   at System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(InternalContext c)
   at System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input)
   at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action)
   at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()
   at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
   at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
   at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
   at System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()
   at System.Linq.Queryable.Count[TSource](IQueryable`1 source)
   at System.Data.Entity.Migrations.History.HistoryRepository.Exists[TContext](HistoryContextBase`1 context)
   at System.Data.Entity.Migrations.History.HistoryRepository.GetPendingMigrations(IEnumerable`1 localMigrations)
   at System.Data.Entity.Migrations.DbMigrator.GetPendingMigrations()
   at System.Data.Entity.Migrations.Infrastructure.MigratorBase.GetPendingMigrations()
   at System.Data.Entity.Migrations.Design.ToolingFacade.GetPendingMigrationsRunner.RunCore()
   at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
Failed to set database initializer of type 'System.Data.Entity.MigrateDatabaseToLatestVersion' for DbContext type 'ToDoListApp.Models.ToDoDb, ToDoListApp' specified in the application configuration. See inner exception for details.
4

1 に答える 1

1

修繕 -

SQLサーバーオブジェクトエクスプローラーにログインし、テーブルの下のEdmMetadataを削除し、web.configに接続文字列を入力するだけで済みます.誰かがこれを読んで同じ問題を抱えていた場合の例を次に示します..

<add name="DefaultConnection" connectionString="server=tcp:* insert server name*.database.windows.net,1433;Database=* insert database name *;User ID=*insert username *@* insert server name*;Password={*insert password here *};Trusted_Connection=False;Encrypt=True;Connection Timeout=30;"  />
于 2012-12-13T16:45:19.247 に答える