我正在 ASP.NET MVC 中开发一个项目。我想在应用程序的数据访问层和业务逻辑层之间创建一个抽象层。我一直在使用存储库和工作单元。回顾一下,在此模式中,创建了一个通用存储库和许多特定存储库。我在这个项目中遇到的问题是我需要另一个存储库中某个特定存储库的方法。例如,我有一个产品和子产品存储库。我想在 Product 方法中使用 Subproduct 方法,而不是每次都为 Subproduct 重写 LINQ 查询。有没有办法扩展存储库设计模式的功能,或者我必须使用另一种设计模式?
public class ProductSubcategoryRepository : Repository<ProductSubcategory>, IProductSubcategoryRepository
{
public ProductSubcategoryRepository(DbContext context) : base(context)
{
}
public IEnumerable<ProductSubcategory> CheckSomeCondition()
{
// LINQ to check some condition based on product subcategory
}
}
public class ProductCategoryRepository : Repository<ProductCategory>, IProductCategoryRepository
{
public ProductCategoryRepository(DbContext context) : base(context)
{
}
public IEnumerable<ProductCategory> GetProductCategoriesBeforeDate()
{
// Repeated LINQ to check some condition based on product subcategory
// (I am looking for a way to call the same method of ProductSubCategory calss)
// LINQ To return List of product category if the previous query is true
}
}
精慕HU
慕森王
慕村9548890
随时随地看视频慕课网APP
相关分类