Created
June 9, 2011 17:43
-
-
Save kristofclaes/1017271 to your computer and use it in GitHub Desktop.
Getting the previous photo
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
// When I run this code when no previous photo should be found, I get | |
// an exception saying "Query returned multiple rows; cannot return | |
// scalar value.". This is strange because it shouldn't return _any_ | |
// values and because I use ".Take(1)" to make sure only one row is | |
// returned. | |
string previousSlug = DB.Photos | |
.Query() | |
.Select(DB.Photos.Slug) | |
.Where(DB.Photos.Published == true && DB.Photos.DatePublished < photo.DatePublished.Value) // There is no published photo with a smaller DatePublished than the one I check against | |
.OrderByDatePublishedDescending() | |
.Take(1) // Should return only one record no matter what | |
.ToScalarOrDefault<string>(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment