0

My model is (simplified version):

Album (ID, Name)

Picture (ID, AlbumID, File). Please note the FK to Albums.

I want to write a query to return the most recent albums (top 10), but just the first 5 pictures of each albums.

I wrote: _context.Albums.Include("Pictures").Take(10).ToList();

In this case, SQL will return the top 10 albums, but ALL pictures for these albums. However in some cases each album may have hundreds of pictures, so I would like a query to limit the number of pictures to 5, for example.

4

1 に答える 1

4

テストされていませんが、おそらくそのようなものです。

_context.Albums.Select(m => new {
     album = m,
     pictures = m.Pictures.Take(5)
}).Take(10);
于 2012-09-03T15:14:05.903 に答える