【发布时间】:2020-05-02 19:10:07
【问题描述】:
我正在使用 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; }
}
}
我的步骤截图
我如何创建我的控制器:enter image description here
输出
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)
【问题讨论】:
-
检查这里它会帮助你stackoverflow.com/a/47071988/2419696
-
@PrasadPhule 我已经试过了。发生同样的错误
标签: c# entity-framework visual-studio-2019 dbcontext asp.net-core-3.1