Jac*_* He 8 .net c# asp.net entity-framework ef-code-first
我是在c#中使用Code First的新手.在我的项目中启用迁移并启动我的网站后,出现错误:
Method 'ExecuteAsync' in type 'System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy' from assembly 'EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' does not have an implementation.
Run Code Online (Sandbox Code Playgroud)
我已经定义了上下文类,如下所示.
namespace MyOA.Migration.Contexts
{
public class OADBContext : DbContext
{
public OADBContext() { }
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试在Global.asax中创建数据库,如下所示.
protected void Application_Start()
{
// Forces initialization of database on model changes.
using (var context = new Migration.Contexts.OADBContext())
{
context.Database.Initialize(force: true);
}
}
Run Code Online (Sandbox Code Playgroud)
我试图搜索原因但不知道.有什么建议?提前致谢.
如果您检查两个程序集的.NET版本:
您将看到 EntityFramework.SqlServer 具有 v4.0 .NET 依赖项,但 EntityFramework 使用 v4.5。这就是问题的根源。我使用dotpeek工具来检查程序集版本(还有其他选项,从堆栈溢出到检查程序集的 .net 版本)。
注意:实际上,当您使用 jetBrains 反射器工具反编译 EntityFramework.SqlServer.dll 时,您会发现没有 ExecuteAsync 方法。
我们要做的就是使用 nuget.exe 来解决这个问题(来自 Visual Studio 或独立的 nuget 可执行文件:请找到“latest nuget.exe”)。并从命令行运行它:
cd "[path to your nuget.exe]"
nuget Install EntityFramework
Run Code Online (Sandbox Code Playgroud)
将下载一组 EF 6 程序集。使用 .net v4.5 文件夹中的 EntityFramework 和 EntityFramework.SqlServer。
| 归档时间: |
|
| 查看次数: |
4498 次 |
| 最近记录: |