Paging Entities (of Aggregates) in Repository with Entity Framework (EF)

Viewed 1659

Suppose I have the following aggregate root:

public class Aggregate
{
    public int Id {get; set;}

    public List<Entity> Entities {get; set;}
}

And the following repository:

public class AggregateRepository
{
   public Aggregate GetPaged(int Id)
   {
     return db.Aggregate
              .Include(x=>x.Entities)
              .Find(id)             
   }
}

Question: how can I get a paged and sort list of entities? Which is the best approach to get the entities paged and sorted, but also with the aggregate information?

Edited:

What are you think about the following approach?

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);        
       }
    }

Instead of return an aggregate object, I can receive a list of entities (20 entities, in this case) with aggregate object included. Is it a good approach working with an aggregate in DDD pattern?

2 Answers
Related