EF Migrations error: could not load type 'System.Data.Entity.Infrastructure.DbContextInfo'

匿名 (未验证) 提交于 2019-12-03 08:56:10

问题:

I am using ContosoUniversity example. I have just used Nuget to download and install code first migrations pakage. Whe I excecute update-database command it throws an error . Is there anything to do more than installing nuget package?

Update-Database : Could not load type 'System.Data.Entity.Infrastructure.DbContextInfo' from assembly 'EntityFramework, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. At line:1 char:16 + update-database <<<<      + CategoryInfo          : NotSpecified: (:) [Update-Database], TypeLoadException     + FullyQualifiedErrorId : System.TypeLoadException,System.Data.Entity.Migrations.Commands.MigrateCommand 

Edit , Now I have installed ADO.NET Entity Framework 4.1 - Update 1 and now it throws an error

Update-Database : The project 'ContosoUniversity' does not contain or reference any contexts. At line:1 char:16 + update-database <<<<      + CategoryInfo          : NotSpecified: (:) [Update-Database], InvalidOperationException     + FullyQualifiedErrorId : System.InvalidOperationException,System.Data.Entity.Migrations.Commands.MigrateCommand 

I have tried the scenario in microsoft blog but nothing changed. ( http://blogs.msdn.com/b/adonet/archive/2011/07/27/code-first-migrations-august-2011-ctp-released.aspx )

回答1:

Try installing the msi.

http://www.microsoft.com/download/en/details.aspx?id=26825

The second error that you are getting sounds like it s having problems identifying a context within your project. Make sure that you have a class that inherits from DbContext.

I would also check that your project is referencing the correct version of the Entity Framework - 4.1 Update 1. Depending on the project type, you should be able to locate the reference in question within the References folder within your project. You may need to click on the 'Show All Files' button (second from the left in the toolbar at the top of the Solution Explorer).

Once you have the reference selected, you will see information such as the path of the DLL and its version in the Properties pane (F4 if it is not already visible).

Edit: According to JTew below, a restart of Visual Studio is required.



回答2:

Had the same error.

I had:

  • Installed EF 4.1 (the older version) via an .msi
  • Installed the newer version (EF 4.1 Update 1 Migrations Alpha 3) via NuGet

This error turned out to be the framework complaining because it was getting the older 4.1.0.0 from the GAC.

Uninstalling the older EF 4.1 did the trick.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!