使用Entity Framework Core添加迁移时出现错误 [英] I get an error when I add migration using Entity Framework Core
问题描述
我建立了一个控制台项目,并首先使用代码将模型映射到数据库.当我运行 Add-Migration InitialMigration
的命令时,出现错误:
I built a console project and use code first to map model to database. When I run the command of Add-Migration InitialMigration
, I get an error:
来自程序集'Microsoft.EntityFrameworkCore.SqlServer,版本= 3.1.5.0,区域性=中性,PublicKeyToken = adb9793829ddae60'的类型'Microsoft.EntityFrameworkCore.SqlServer.Query.Internal.SqlServerSqlTranslatingExpressionVisitorFactory'中的方法'Create'没有实现
Method 'Create' in type 'Microsoft.EntityFrameworkCore.SqlServer.Query.Internal.SqlServerSqlTranslatingExpressionVisitorFactory' from assembly 'Microsoft.EntityFrameworkCore.SqlServer, Version=3.1.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.
DbContext
是:
class ActorDbContext : DbContext
{
public DbSet<Actor> Actors { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(
@"Server=(localdb)\mssqllocaldb;Database=ActorDb;"
+ "Trusted_Connection=True;");
}
}
实体为:
public class Actor
{
public int Id { get; set; }
public String Name { get; set; }
public int Age { get; set; }
public bool AcademyWinner { get; set; }
}
推荐答案
我只是使用 VS for Mac
遇到了同样的问题.我的问题是我安装了以下版本的软件包:
I just ran into this same issue using VS for Mac
.
My problem was I had the following versions of packages installed:
- Microsoft.EntityFrameworkCore.Tools
5.0.0-preview.8.20407.4
- Microsoft.EntityFrameworkCore.Design
5.0.0-preview.8.20407.4
- Microsoft.EntityFrameworkCore.SqlServer
3.1.8
记下使用的不同版本.为了解决此问题,我卸载了软件包的 preview
版本并安装了最新的稳定版本.
Take note of the different versions used.
To correct the issue I uninstalled the preview
versions of the packages and installed the latest stable versions.
- Microsoft.EntityFrameworkCore.Tools
3.1.8
- Microsoft.EntityFrameworkCore.Design
3.1.8
- Microsoft.EntityFrameworkCore.SqlServer
3.1.8
再次记下所有3个软件包的版本.一旦我为每个软件包安装了正确的版本,问题就解决了,我的 Add-Migration
工作了.
Again take note of the versions for all 3 packages.
Once I had installed the correct version of each package the issue was resolved and my Add-Migration
worked.
这篇关于使用Entity Framework Core添加迁移时出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!