[英]DbContext Issues Upgrading from .NET Core 1 to .NET 5
I have an older program running on .NET Core 1 and want to get it working with .NET 5. Instead of going through the tedious process of upgrading each version step by step I decided to just create a new solution and start from scratch.我有一个旧程序在 .NET Core 1 上运行,并希望它与 .NET 5 一起工作。我没有经历逐步升级每个版本的繁琐过程,而是决定只创建一个新解决方案并从头开始。 Doing this, I am able to copy most files from the older projects.这样做,我可以从旧项目中复制大部分文件。
My issue is in the DbContext classes.我的问题出在 DbContext 类中。
public partial class ClassName : DbContext
There are a number of errors throughout, but each give me the same (or similar) suggestion to resolve them, relating to a missing using reference.整个过程中有许多错误,但每个错误都给我相同(或相似)的建议来解决它们,与缺少使用参考有关。
The type or namespace name 'DbContext' could not be found (are you missing a using directive or an assembly reference?) Cannot resolve symbol 'DbContext'
Now, I know I am missing the using Microsoft.EntityFrameworkCore;
现在,我知道我错过了using Microsoft.EntityFrameworkCore;
reference.参考。 So when I add that package to the project, my file changes and I now get about 500 errors (about half the lines in the file).因此,当我将 package 添加到项目中时,我的文件发生了变化,我现在收到大约 500 个错误(文件中大约一半的行)。
Some examples of these new errors are as follows:这些新错误的一些示例如下:
entity.HasKey(e => e.Id)
.HasName("PK");
entity.ToTable("TB");
In the above snippet, .HasName
is throwing the error 'KeyBuilder' does not contain a definition for 'HasName' and no accessible extension method 'HasName' accepting a first argument of type 'KeyBuilder'.
在上面的代码片段中, .HasName
抛出错误'KeyBuilder' does not contain a definition for 'HasName' and no accessible extension method 'HasName' accepting a first argument of type 'KeyBuilder'.
As someone new to entity framework, am I missing something obvious or should I be re-scaffolding the database to re-create these context files?作为实体框架的新手,我是否遗漏了一些明显的东西,或者我应该重新搭建数据库以重新创建这些上下文文件?
No answer here yet so someone might miss that the comments actually holds an answer.这里还没有答案,所以有人可能会错过评论实际上包含答案。
As @Kirk Larkin states in a comment to the question the solution is to add the Microsoft.EntityFrameworkCore.Relational
package.正如@Kirk Larkin 在对该问题的评论中所述,解决方案是添加Microsoft.EntityFrameworkCore.Relational
package。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.