entity-framework - dotnet-aspnet-codegenerator 脚手架控制器:找不到主键
问题描述
在 VS Code 中使用 netcoreapp3.1(3.1.6 库)
我已经构建了一个简单的 web api 项目,对我的数据库 ( dotnet ef dbcontext scaffold
) 进行了反向工程,其中包含没有键的视图,这应该不再是问题了。
我可以看到在onModelCreating
代码中添加了以澄清没有密钥:
modelBuilder.Entity<VwAverageRuns>(entity =>
{
entity.HasNoKey();
当我去生成一个控制器时,问题就出现了:
dotnet aspnet-codegenerator controller -name VwAverageRunsController -async -api -m VwAverageRuns -dc dbContext -outDir Controllers
它错误:
试图找出模型和 DbContext 的 EntityFramework 元数据:
未找到“VwAverageRuns”主键。在 Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.b__6_0()
在 Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
在 Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.Execute(String[] args)
在 Microsoft .VisualStudio.Web.CodeGeneration.CodeGenCommand.Execute(String[] args)
但是从我读过的所有内容来看,hasNoKey()
里面onModelCreating
应该意味着我不需要指定密钥。这里发生了什么?
解决方案
推荐阅读
- python - 如何在条形图上绘制一条垂直线,其日期时间标签只有谨慎的 x 轴刻度位置?
- assembly - 如何在asm中的函数序言之前中断
- azure - Terraform AZ CLI 本地执行命令限制
- javascript - 如何根据单元格值将 Google Sheet 中的数据显示到 Google Web App?
- javascript - 使用 PptxGenJS 向 PowerPoint 幻灯片添加过渡
- python - 在 KeyCloak 中绕过“执行以下操作”?
- facebook - 如何为 Instagram 基本显示 API 实现 Instagram 或 Facebook 登录按钮的继续?
- c++ - 错误:非静态引用成员 - 不能使用默认赋值运算符
- linux - 在 julia 中设置 pandas 时出错:找不到键“_IXIndexer”
- wpf - 如何根据 ComboBox 的选择显示不同的用户控件?