EF 迁移错误:无法加载类型“System.Data.Entity.Infrastruct.DbContextInfo”
我正在使用 ContosoUniversity 示例。我刚刚使用 Nuget 下载并安装代码优先迁移包。当我执行 update-database 命令时,它会抛出错误。除了安装 nuget 包还有什么可以做的吗?
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
编辑, 现在我已经安装了ADO.NET Entity Framework 4.1 - Update 1
,现在它抛出一个错误
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
我已经尝试了微软博客中的场景,但没有任何改变。 ( http://blogs.msdn.com/b/adonet/archive/2011/07/27/code-first-migrations-august-2011-ctp-released.aspx )
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 )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试安装 MSI。
http://www.microsoft.com/download/en/details.aspx ?id=26825
您收到的第二个错误听起来像是在识别项目中的上下文时遇到问题。确保您有一个继承自 DbContext 的类。
我还将检查您的项目是否引用了正确版本的实体框架 - 4.1 Update 1。根据项目类型,您应该能够在项目内的 References 文件夹中找到相关引用。您可能需要单击“显示所有文件”按钮(解决方案资源管理器顶部工具栏中左侧第二个)。
选择引用后,您将在“属性”窗格中看到诸如 DLL 路径及其版本之类的信息(如果尚不可见,则按 F4)。
编辑:根据下面的 JTew,需要重新启动 Visual Studio。
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.
有同样的错误。
我有:
这个错误结果是框架抱怨,因为它从广汽集团。
卸载旧的 EF 4.1 就可以了。
Had the same error.
I had:
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.