【发布时间】:2017-07-12 10:33:47
【问题描述】:
假设我有以下聚合根:
public class Aggregate
{
public int Id {get; set;}
public List<Entity> Entities {get; set;}
}
还有以下存储库:
public class AggregateRepository
{
public Aggregate GetPaged(int Id)
{
return db.Aggregate
.Include(x=>x.Entities)
.Find(id)
}
}
问题:如何获得分页和排序的实体列表?对实体进行分页和排序以及汇总信息的最佳方法是什么?
已编辑:
您对以下方法有何看法?
public class AggregateRepository
{
public IEnumerable<Entity> GetEntitiesPaged(int id)
{
return db.Aggregate
.Include(x=>x.Aggregate)
.Where(x=>x.Id = id)
.Select(x=>x.Entities)
.Take(20);
}
}
我可以接收包含聚合对象的实体列表(在本例中为 20 个实体),而不是返回聚合对象。在 DDD 模式中使用聚合是一种好方法吗?
【问题讨论】:
-
为了给你一个有用的答案,我想知道你想通过分页和排序的实体列表来实现什么。 - 您的写入或读取模型中是否需要分页和排序的实体列表? - 您打算使用此页面向用户显示实体吗? - 您是否要逐页阅读(查询)实体以在您的域中强制执行一些不变量?
标签: c# entity-framework domain-driven-design repository-pattern