为什么我使用 entity framework 添加新的剃须刀页面时出现 "Type does not exist" 错误
Why am I getting "Type does not exist" error adding a new razor page using entity framework
我正在试验 Visual Studio 2022 和 EF Core 6。我创建了一个包含三个项目的解决方案,一个是我的剃刀页面,一个是我的 dbcontext,一个是我的实体。我能够毫无问题地进行迁移,创建数据库和单个 table,这对我来说表明我一切正常,但是当我去添加一个剃刀页面并允许 VS 连接一个“列表“我的模板,它旋转了一分钟并给我一个错误:名称为 Scaffolding.Entities.EncylopediaEntry 的类型不存在。
这是显然不存在的class
using System.ComponentModel.DataAnnotations;
namespace Scaffolding.Entitites
{
public class EncylopediaEntry
{
public Guid Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}
}
现在这里是带有硬编码连接字符串的 DbContext,因为我正试图弄清楚为什么脚手架不起作用
using Microsoft.EntityFrameworkCore;
using Scaffolding.Entitites;
namespace ScaffoldingTest.Data
{
public class ScaffoldingContext : DbContext
{
public DbSet<EncylopediaEntry> encyclopediaEntries { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer("{remove}");
}
}
}
我遇到了同样的错误。 Visual Studio 2022(也有预览版)使用 NET 6.0。
我安装了 NET 5.0 并使用新项目 net 5 进行了测试,然后运行良好。
但不是 NET 6.0。
我正在试验 Visual Studio 2022 和 EF Core 6。我创建了一个包含三个项目的解决方案,一个是我的剃刀页面,一个是我的 dbcontext,一个是我的实体。我能够毫无问题地进行迁移,创建数据库和单个 table,这对我来说表明我一切正常,但是当我去添加一个剃刀页面并允许 VS 连接一个“列表“我的模板,它旋转了一分钟并给我一个错误:名称为 Scaffolding.Entities.EncylopediaEntry 的类型不存在。
这是显然不存在的class
using System.ComponentModel.DataAnnotations;
namespace Scaffolding.Entitites
{
public class EncylopediaEntry
{
public Guid Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
}
}
现在这里是带有硬编码连接字符串的 DbContext,因为我正试图弄清楚为什么脚手架不起作用
using Microsoft.EntityFrameworkCore;
using Scaffolding.Entitites;
namespace ScaffoldingTest.Data
{
public class ScaffoldingContext : DbContext
{
public DbSet<EncylopediaEntry> encyclopediaEntries { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer("{remove}");
}
}
}
我遇到了同样的错误。 Visual Studio 2022(也有预览版)使用 NET 6.0。 我安装了 NET 5.0 并使用新项目 net 5 进行了测试,然后运行良好。 但不是 NET 6.0。