C# 具有混合逻辑的存储库模式

C# 具有混合逻辑的存储库模式,c#,repository-pattern,C#,Repository Pattern,我的ProductRepository有一个方法,比如说: GetAllCalculatedProducs(int categoryId) {} 该方法使用类计算器来计算乘积的许多值。它看起来就像这样: public IEnumerable<Product> GetAllCalculatedProducts(int categoryId) { var items = GetAllProductsByCategoryId(categoryId); Calculator c

我的ProductRepository有一个方法,比如说:

GetAllCalculatedProducs(int categoryId) {}
该方法使用类计算器来计算乘积的许多值。它看起来就像这样:

public IEnumerable<Product> GetAllCalculatedProducts(int categoryId)
{
  var items = GetAllProductsByCategoryId(categoryId);

  Calculator c = new Calculator(items);
  c.Calculate();

  Filter f = new Filter(c.Items);
  f.Filter();

  Sorter s = new Sorter(f.Items);
  s.Sort();

  return s.Items;
}
public IEnumerable GetAllCalculatedProducts(int categoryId)
{
var项目=GetAllProductsByCategoryId(categoryId);
计算器c=新的计算器(项目);
c、 计算();
过滤器f=新过滤器(c项);
f、 过滤器();
分拣机s=新分拣机(f.项目);
s、 排序();
归还美国物品;
}
计算器使用另一个存储库完成他的工作

[数据库][储存库] [计算器]

我认为这是错误的,因为存储库使用属于逻辑的类。我甚至认为这种方法应该在其他地方,也许在ProductService中?但我不确定


在存储库中可以使用筛选和排序吗?

我只向存储库添加直接或间接对数据库起作用的方法。您的方法不这样做,它调用与DB一起工作的
GetAllProductsByCategoryId
。因此,它应该成为服务的一部分


如果它生成了自己的查询并对其进行了一些过滤和排序,我就不会有任何问题。

谢谢您的回复,所以解决方案可能是这样的:,对吗?是的。虽然我会为
分拣机
过滤器
计算器
使用更具体的名称。可能是
SortOnLastName
FilterOutOldEntries
calculatearageprice