【发布时间】:2018-10-02 07:15:20
【问题描述】:
我读过 Repositories 不应该使用 IQueryable。简单的存储库示例有 ListAll、FindById、Add、Delete。下面是一个示例产品存储库 ListAll。如果我不能覆盖查询,并且需要搜索查询,例如按类别的 ProductTable 或按重量的 ProductTable(复杂查询),那么我将需要一个 DAO(数据访问对象模式)。
所以问题是,
(a) 可以在同一个应用程序中同时使用存储库模式和 DAO 模式吗?
(b) 这不是绕过了拥有 DDD 存储库模式的全部要点吗?
如何在访问存储库的同时访问具有复杂请求的 ProductTable?第一个存储库查询会很慢。
public virtual IEnumerable<Products> List()
{
return _dbContext.Products.AsEnumerable();
}
// This repository pattern will be slow, first it access all product and Then filters
var result = context.products()
.Where(o => o.ProductCategoryId== 5);
// This is dao pattern, with more specific queries
var result = context.products.AsEnumerable()
.Where(o => o.ProductCategoryId== 5);
Entity Framework Repository Pattern why not return Iqueryable?
【问题讨论】:
-
您可以使用here所使用的规范方法
标签: c# asp.net-core repository domain-driven-design asp.net-core-2.0