Skip to content

Instantly share code, notes, and snippets.

@ToJans
Forked from kristofclaes/gist:1008780
Created June 8, 2011 09:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ToJans/1014127 to your computer and use it in GitHub Desktop.
Save ToJans/1014127 to your computer and use it in GitHub Desktop.
Retrieving next and previous records with Simple.Data
// Checked blog at http://blog.markrendle.net/2011/05/23/simple-data-0-6-5/
// and code at https://github.com/markrendle/Simple.Data/blob/master/Simple.Data/SimpleQuery.cs
int? previousPhotoId = DB.Photos.Query()
.Select(DB.Photos.Id)
.Where(DB.Photos.Published == true && DB.Photos.DatePublished < currentPhoto.DatePublished.Value)
.OrderByDatePublishedDescending()
.ToScalarOrDefault<int?>();
int? nextPhotoId = DB.Photos.Query()
.Select(DB.Photos.Id)
.Where(DB.Photos.Published == true && DB.Photos.DatePublished > currentPhoto.DatePublished.Value)
.OrderByDatePublishedAscending()
.ToScalarOrDefault<int?>();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment