启用代码优先实体框架VS Web Express 2012 [英] Enabling Code First Entity Framework VS Web Express 2012

查看:115
本文介绍了启用代码优先实体框架VS Web Express 2012的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Visual Studio Web Express 2012中启用代码优先。从目前为止我已经看到,我必须使用软件包管理器控制台和启用迁移命令。当我这样做,我得到以下错误。

I am trying to enable Code First in my Visual Studio Web Express 2012. From what I have read so far I have to use the Package Manager Console and the command Enable-Migrations. When I do this I get the following error.

Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///E:\Working\wingtoysdl\C#\packages\EntityFramework.5
.0.0\tools\EntityFramework.PowerShell.Utility.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)"
At E:\Working\wingtoysdl\C#\packages\EntityFramework.5.0.0\tools\EntityFramework.psm1:398 char:62
+     $utilityAssembly = [System.Reflection.Assembly]::LoadFrom <<<< ((Join-Path $toolsPath EntityFramework.PowerShell.Utility.dll))
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

You cannot call a method on a null-valued expression.
At E:\Working\wingtoysdl\C#\packages\EntityFramework.5.0.0\tools\EntityFramework.psm1:399 char:50
+     $dispatcher = $utilityAssembly.CreateInstance <<<< (
    + CategoryInfo          : InvalidOperation: (CreateInstance:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Exception calling "CreateInstanceFrom" with "8" argument(s): "Could not load file or assembly 'file:///E:\Working\wingtoysdl\C#\packages\EntityF
ramework.5.0.0\tools\EntityFramework.PowerShell.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515
)"
At E:\Working\wingtoysdl\C#\packages\EntityFramework.5.0.0\tools\EntityFramework.psm1:431 char:31
+     $domain.CreateInstanceFrom <<<< (
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

正如你所看到的,这是一个非常大的错误,使得Google很难和疑难解答有人对我有什么想法吗可以解决这个问题吗?

As you can see it is a very large error making it very hard to google and troubleshoot. Does anyone have any ideas on how I can fix this?

推荐答案

我已经遇到这个问题了两次。两次我不得不卸载实体框架,然后为解决方案中的每个项目重新安装它。有一件事我花了一段时间才明白我第二次这样做是因为我重新安装了实体框架后才重新启动Visual Studio(2012)(或者我继续得到无法加载文件或程序集 [路径] \packages\EntityFramework.5
.0.0\tools\EntityFramework.PowerShell.Utility.dll'错误)。

I've run into this issue twice now. Both times I've had to uninstall entity framework then re-install it for each project in the solution. One thing that took me a while to figure out the second time I did this is that I had to re-start Visual Studio (2012) after re-installing Entity Framework (or I continued to get the "Could not load file or assembly '[path]\packages\EntityFramework.5 .0.0\tools\EntityFramework.PowerShell.Utility.dll'" error).

进入软件包管理器控制台转到:工具 - >库软件包管理器 - >软件包管理器控制台

To get to the Package Manager Console go to: Tools -> Library Package Manager -> Package Manager Console

在软件包管理器中卸载实体框架每个项目(我从包管理器控制台顶部的默认项目下拉列表中选择了每个项目):

卸载包实体框架-Force

In the Package Manager uninstall Entity Framework for each project (I selected each project from the Default Project dropdown at the top of the Package Manager Console):
Uninstall-Package EntityFramework -Force

然后为每个项目安装它:

安装包实体框架

Then install it for each project:
Install-Package EntityFramework

此时尝试运行Enable-Migrations命令给出了错误,直到我关闭并重新启动Visual Studio。然后它成功,Update-Database命令(在Migrations.Configuration文件中将AutomaticMigrationsEnabled设置为true)之后。

At this point attempting to run the Enable-Migrations command gave the error still, until I closed and restarted Visual Studio. Then it was successful, as was the Update-Database command (after setting AutomaticMigrationsEnabled to true in the Migrations.Configuration file).

这篇关于启用代码优先实体框架VS Web Express 2012的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆