dotnet-aspnet-codegenerator脚手架控制器:找不到主键

时间:2020-08-04 14:53:15

标签: entity-framework asp.net-web-api2

在VS Code中使用netcoreapp3.1(3.1.6库)

我建立了一个简单的Web api项目,对我的数据库(dotnet ef dbcontext scaffold)进行了反向工程,该数据库包含无键的视图,shouldn't be a problem anymore

我可以看到在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意味着我不需要指定键。这是怎么回事?

0 个答案:

没有答案