c# - 问题,VS 19 ASP.NET Core 3.1,当我开始创建“带有视图的 MVC 控制器,使用实体框架”
问题描述
我正在使用 ASP.NET Core 3.1,我已经创建了控制器,它对我有用,几天后我需要为ShoppingCartItem
.
我的模型
namespace NCCMobileTest.Data.Model
{
public class ShoppingCartItem
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
public int Quantity { get; set; }
public string Category { get; set; }
public string Color { get; set; }
public string Brand { get; set; }
public string Barcode { get; set; }
// from Item table
public int Item_Id { get; set; }
public Customer customer { get; set; }
// from generat bill no
public int Bill_No { get; set; }
}
}
我的DbContext
namespace NCCMobileTest.Data
{
public class ApplicationDbContext : IdentityDbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options): base(options)
{
}
public DbSet<ShoppingCartItem> ShoppingCartItems { get; set; }
}
}
我的一些步骤截图
输出
Finding the generator 'controller'...
Running the generator 'controller'...
Attempting to compile the application in memory.
Could not get the reflection type for DbContext : NCCMobileTest.Data.ApplicationDbContext
at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.<BuildCommandLine>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)
解决方案
最近我遇到了类似的问题。经过数小时的怀疑和调试,我明白问题在于我已将我的Startup
课程重命名为StartUp
,这导致了整个错误。
我不能确定这是否确实是您的问题,但值得检查一下。
推荐阅读
- excel - 如何在 Excel 中自动化非并发的特定行高
- ssl - 同时使用 SSL 和 Cloudflare 是一个好的过程吗?
- ssis - 并行 ssis 执行
- node.js - 将微服务节点 js 应用程序部署到 heroku
- java - Java 停止声音按钮无法正常工作
- r - 快速调整 r 平方提取
- python - 在 dockerfile 中使用 python secrets 模块是否安全?
- firebase - Firebase 托管,如何一次在多个帐户上部署相同的代码
- configuration - Mercurial 中特定于存储库的特殊/点文件
- python - 每个 id 创建 n 行 | 熊猫