Created
          June 5, 2011 08:21 
        
      - 
      
- 
        Save kristofclaes/1008780 to your computer and use it in GitHub Desktop. 
    Retrieving next and previous records with Simple.Data
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // This code works, but somehow it looks like there is a better and more elegant solution for it. | |
| IEnumerable<Models.Photo> previous = DB.Photos | |
| .FindAll(DB.Photos.Published == true && DB.Photos.DatePublished < currentPhoto.DatePublished.Value) | |
| .OrderByDatePublishedDescending() | |
| .Take(1) | |
| .Cast<Models.Photo>(); | |
| int? previousPhotoId = null; | |
| Models.Photo previousPhoto = previous.FirstOrDefault(); | |
| if (previousPhoto != null) | |
| { | |
| previousPhotoId = previousPhoto.Id; | |
| } | |
| IEnumerable<Models.Photo> next = DB.Photos | |
| .FindAll(DB.Photos.Published == true && DB.Photos.DatePublished > currentPhoto.DatePublished.Value) | |
| .OrderByDatePublished() | |
| .Take(1) | |
| .Cast<Models.Photo>(); | |
| int? nextPhotoId = null; | |
| Models.Photo nextPhoto = next.FirstOrDefault(); | |
| if (nextPhoto != null) | |
| { | |
| nextPhotoId = nextPhoto.Id; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment