首页 > 解决方案 > 问题,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)

标签: c#entity-frameworkvisual-studio-2019dbcontextasp.net-core-3.1

解决方案


最近我遇到了类似的问题。经过数小时的怀疑和调试,我明白问题在于我已将我的Startup课程重命名为StartUp,这导致了整个错误。

我不能确定这是否确实是您的问题,但值得检查一下。


推荐阅读