c# - 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 的一部分(我所做的一切都与书中的相同!)。
我用谷歌搜索了这个,我只找到了这个答案:“这个对象在你的数据库中不存在”。
解决方案
推荐阅读
- python - Python3 AttributeError:模块're'没有属性'split'
- html - YouTube 和 Twitch 如何覆盖带音频视频的自动播放策略?
- php - Laravel - 在保存的事件中保存许多相关模型在更新时不起作用
- javascript - 从多文件输入中获取文件 url[type="file"]
- c# - LibvclSharp winforms 转到特定时间
- vue.js - 当进入 :src 的变量为空时怎么办?
- laravel - 拼命在 Laravel 中寻找一个非空的 $_ENV
- c++ - 是否允许向空指针添加零?
- java - 我可以使用用户提供的参数在 Android Studio 中创建自定义类,以将数据存储在 Firebase RT DB 中吗
- applescript - Applescript 获取名称异常