I added an API project to my project. Although I have given all references when I run it, I get the following error. How can I fix?
This is my startup file:
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
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();
});
}
}
Although I have added all references in my project, I am encountering this error. Despite a lot of research, I could not figure it out. Please help me.
If I have other project files I need to add, I can.
This is my EfCoreProductRepository file:
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 page, 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 page, 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();
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…