问题描述
我在我的项目中添加了一个 API 项目。虽然我在运行时已经给出了所有引用,但出现以下错误。我该如何解决?
这是我的启动文件:
公开课启动 { 公共启动(IConfiguration配置) { 配置=配置; }
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddScoped(typeof(ShopContext));
services.AddDbContext<ShopContext>(options => options.UseSqlServer(Configuration["ConnectionStrings:SqlConStr"].ToString(),o =>
{
o.MigrationsAssembly("BuyfiletData");
}));
services.AddScoped(typeof(IRepository<>),typeof(EfCoreGenericRepository<>));
services.AddScoped<IProductRepository,EfCoreProductRepository>();
services.AddScoped<IProductService,ProductManager>();
services.AddControllers();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app,IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
虽然我已经在我的项目中添加了所有引用,但我遇到了这个错误。尽管进行了大量研究,但我无法弄清楚。请帮我。 如果我有其他项目文件需要添加,我可以。
这是我的 EfCoreProductRepository 文件:
public class EfCoreProductRepository : EfCoreGenericRepository<Product>,IProductRepository
{
private ShopContext _context { get=>_context as ShopContext;}
public EfCoreProductRepository(DbContext context) : base(context)
{
}
public List<Product> GetProductsWithCategory(string name,int page,int pageSize)
{
var products = _context.Products.AsQueryable();
if (!string.IsNullOrEmpty(name))
{
products = products.Include(i => i.ProductCategories)
.ThenInclude(i => i.BasicCategory)
.Where(i => i.ProductCategories.Any(a =>
a.BasicCategory.Name.ToLower() == name.ToLower() || a.MainCategory.Name.ToLower()==name.ToLower() ||a.SubCategory.Name.ToLower()== name.ToLower()));
}
return products.Skip((page - 1) * pageSize).Take(pageSize).ToList();
}
public List<Product> GetProductsWithFilters(List<Product> productList,int pageSize,int maxPrice,int minPrice)
{
var products = _context.Products.AsQueryable();
/*products= products.Where(i => i.Brand == product.Brand && i.Point == product.Point&& i.Variety == product.Variety&& i.Size == product.Size&& i.Color == product.Color&& i.Gender == product.Gender);*/
foreach (var product in productList)
{
products = products.Where(i =>
i.Brand == product.Brand && i.Point == product.Point && i.Variety == product.Variety &&
i.Size == product.Size && i.Color == product.Color && i.Gender == product.Gender);
}
products.Where(i => i.Price > minPrice && i.Price < maxPrice);
return products.Skip((page - 1) * pageSize).Take(pageSize).ToList();
}
public List<Product> GetProductsWithSearch(string word,int pageSize)
{
var products = _context.Products.Where(i=>i.Brand.Contains(word.ToLower())|| i.MainCategory.Contains(word.ToLower())|| i.Category.Contains(word.ToLower()) || i.Details.Contains(word.ToLower())).AsQueryable();
return products.Skip((page - 1) * pageSize).Take(pageSize).ToList();
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)