首页 > 解决方案 > SqlException:无效的对象名称“产品”。处于生产模式但处于开发模式时

问题描述

public ViewResult List(string category , int productPage = 1) => View(new ProductsListViewModel
{
    Products = repository.Products
                         .Where(p=> category == null || p.Category == category)
                         .OrderBy(p => p.ProductID)
                         .Skip((productPage - 1) * PageSize)
                         .Take(PageSize),
                PagingInfo = new PagingInfo
                {
                    CurrentPage = productPage,
                    ItemsPerPage = PageSize,
                    TotalItems = category == null ? repository.Products.Count() : repository.Products.Where(e => e.Category == category).Count()
                },
                CurrentCategory = category
            }); 

这是我的错误出现的部分。

我做了这两个类的迁移。

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.EntityFrameworkCore.Infrastructure;


namespace SportsStore.Models
{
    public class ApplicationDbContext : DbContext
    {
        public ApplicationDbContext(DbContextOptions<ApplicationDbContext>options) : base(options) { }

        public DbSet<Product> Products { get; set; }
        public DbSet<Order>Orders { get; set; } 
    }
}

第二个是:

using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;

namespace SportsStore.Models
{
    public class AppIdentityDbContext : IdentityDbContext<IdentityUser>
    {
        public AppIdentityDbContext(DbContextOptions<AppIdentityDbContext> options) : base(options) { }
    }
}

真的我不知道该怎么办。

我想在 Azure 上托管这个项目。它是 Adam Freeman 的 PRO MVC CORE 2 的一部分(我所做的一切都与书中的相同!)。

我用谷歌搜索了这个,我只找到了这个答案:“这个对象在你的数据库中不存在”。

标签: c#entity-framework-core

解决方案


推荐阅读