问题描述
我更喜欢在c#中使用Code First。在我的项目中启用迁移并启动我的网站后,我收到一个错误:
方法'ExecuteAsync'从程序集'EntityFramework.SqlServer,Version = 6.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089'键入'System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy'没有一个实现。
我已经定义了上下文类如下。
命名空间MyOA.Migration.Contexts
{
public class OADBContext:DbContext
{
public OADBContext(){}
}
}
,我试图在Global.asax中创建数据库,如下所示。
protected void Application_Start()
{
//强制对数据库进行模型更改的初始化。
using(var context = new Migration.Contexts.OADBContext())
{
context.Database.Initialize(force:true);
}
}
我试图搜索原因,但不知道。
任何建议?
提前感谢
如果您检查两个asseblies的.NET版本:
- EntityFramework(v4.5)
- EntityFramework.SqlServer(v4.0)
您将看到EntityFramework.SqlServer具有v4.0 .NET依赖关系,但EntityFramework使用v4.5。这是问题的根源。我使用工具来检查程序集版本()。
注意:当您使用jetBrains反射器工具反编译EntityFramework.SqlServer.dll时,您会发现没有ExecuteAsync方法。
我们要解决的问题是使用nuget.exe(从visual studio或独立的nuget可执行文件:)。并从命令行运行:
cd[路径到你的nuget.exe]
nuget安装EntityFramework
将下载一组EF 6组装。使用.net v4.5文件夹中的EntityFramework和EntityFramework.SqlServer。
I am newer about using Code First in c#.After I enabled Migration in my project and launch my site, I get an Error:
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.
I have defined the context class as below.
namespace MyOA.Migration.Contexts
{
public class OADBContext : DbContext
{
public OADBContext() { }
}
}
and I tried to create the DB in Global.asax as below.
protected void Application_Start()
{
// Forces initialization of database on model changes.
using (var context = new Migration.Contexts.OADBContext())
{
context.Database.Initialize(force: true);
}
}
I tried to search the reason but got no idea.Any suggestions?Thanks in advance.
If you check the .NET version of the two asseblies:
- EntityFramework (v4.5)
- EntityFramework.SqlServer (v4.0)
You will see that EntityFramework.SqlServer has v4.0 .NET dependency, but EntityFramework uses v4.5. That is the root of the issue. I use dotpeek tool for checking the assembly version (there are other options from stack overflow to check .net vestion of an assembly).
Note: and really when you decompile EntityFramework.SqlServer.dll using jetBrains reflector tool you will find that there is no ExecuteAsync method.
What we have to do to fix the issue is to use nuget.exe (from visual studio or from stand alone nuget executable: please find "latest nuget.exe"). And run it from command line:
cd "[path to your nuget.exe]"
nuget Install EntityFramework
A set of EF 6 assemblis will be downloaded. Use the EntityFramework and EntityFramework.SqlServer from .net v4.5 folder.
这篇关于类型“System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy”中的方法“ExecuteAsync”没有实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!