使用Entity Framework Core添加迁移时出现错误

编程入门 行业动态 更新时间:2024-10-24 04:47:25
本文介绍了使用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添加迁移时出现错误

本文发布于:2023-11-14 00:49:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1585767.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:出现错误   Entity   Framework   Core

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!