无法获取DbContext的反射类型 [英] Could not get the reflection type for DbContext
问题描述
在ASP Core 2.0 VS 2017中搭建控制器时,我得到以下信息:
When scaffolding a controller in ASP Core 2.0 VS 2017 I get the following:
无法获取DbContext的反射类型:
Could not get the reflection type for DbContext :
BE.Data.ApplicationDbContext在 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)
BE.Data.ApplicationDbContext at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.b__6_0() at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args) at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.Execute(String[] args) at Microsoft.VisualStudio.Web.CodeGeneration.CodeGenCommand.Execute(String[] args)
这一切突然发生了,运行相同代码的同事没有遇到此问题,我尝试了干净的构建,删除了每个项目中的bin和obj文件夹,删除了db,但我似乎还是无法工作出来,将不胜感激.
This all of a sudden has occurred, and a colleague running the same code does not get this problem, I had tried clean builds, deleting the bin and obj folders in each project, deleting the db and still I cannot seem to work it out, would appreciate any help.
型号:
public class SettingType : BaseModel
{
public int SettingTypeId { get; set; }
public string SettingTypeDescription { get; set; }
public string SystemCode { get; set; }
}
推荐答案
I had this issue too, when I was using the new C#7 feature (expression bodied members and Throw expressions) but by replacing my code with it's equivalent in C#6 it didn't give me that error anymore. Try to test your project without any C#7 new feature and probably it should works fine. I'm not sure what is the reason but I think The Roslyn packages that scaffolding depends on does not support C#7 new features yet.
作为让脚手架与C#7配合使用的一种变通办法,我认为您可以通过以下操作来实现:
As a workaround to let scaffolding works with C#7 I think you can by doing the following:
- 安装(或更新)NuGet软件包
Microsoft.CodeAnalysis.CSharp.Workspaces
2.0.0或更高版本 - 然后重试脚手架
- Install (or update) NuGet package
Microsoft.CodeAnalysis.CSharp.Workspaces
version 2.0.0 or higher - And then retry to scaffolding again
这篇关于无法获取DbContext的反射类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!