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