Проблема, VS 19 ASP. NET Core 3.1, когда я начинаю создавать "MVC Контроллер с представлением, используя Entity Framework" - PullRequest
0 голосов
/ 02 мая 2020

Я использую 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)

Ответы [ 2 ]

0 голосов
/ 02 мая 2020

Недавно я столкнулся с подобной проблемой. После многих часов скептицизма и отладки я понял, что проблема в том, что я переименовал свой класс Startup в StartUp, и это вызвало полную ошибку.

Я не могу быть уверен, что это действительно ваша проблема, но стоит ее проверить.

0 голосов
/ 02 мая 2020

IdentityDbContext наследуется от DbContext?

Если нет, пытались ли вы изменить значение на

public class ApplicationDbContext : DbContext
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...