Skip to content

Instantly share code, notes, and snippets.

@JwanKhalaf
Created June 22, 2019 21:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JwanKhalaf/c7597ac02ad7f9024c9b2b623f9bff24 to your computer and use it in GitHub Desktop.
Save JwanKhalaf/c7597ac02ad7f9024c9b2b623f9bff24 to your computer and use it in GitHub Desktop.
var query = context.Artists.AsNoTracking()
.OrderBy(x => x.FirstName)
.Select(x =>
new ArtistsResponse
{
FirstName = x.FirstName,
LastName = x.LastName,
Slugs = x.Slugs.Select(s => new ArtistSlugResponse { Name = s.Name, IsPrimary = s.IsPrimary }).ToList(),
ImageId = x.Image == null ? 0 : x.Image.Id,
});
var page = query.Paging(offset, limit) // do any filtering via `Where` here, before the paging clause, unless you want TotalCount to take filtering into consideration
.GroupBy(x => new { TotalCount = query.Count() })
.First();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment