jjzjj

GetMaxItemSmth

全部标签

c# - DDD : entity's collection and repositories

假设我有publicclassProduct:Entity{publicIListItems{get;set;}}假设我想找到一个最大的项目...我可以添加方法Product.GetMaxItemSmth()并使用Linq(fromiinItemsselecti.smth).Max())或使用手动循环或其他方式。现在,问题是这会将整个集合加载到内存中。正确的解决方案是进行特定的数据库查询,但域实体无权访问存储库,对吧?所以要么我做productRepository.GetMaxItemSmth(product)(这很丑,不是吗?),或者即使实体可以访问存储库,我也使用来自实体的IPro