Created
July 11, 2010 02:42
-
-
Save atheken/471224 to your computer and use it in GitHub Desktop.
This file contains 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
public Post GetMostRecentPost() | |
{ | |
Post mostRecentPost; | |
using(var db = Mongo.Create("mongodb://localhost/BlogApp")) | |
{ | |
var posts = db.GetCollection<Post>(); | |
//create a LINQ queryable to search the DB. | |
var q = posts.AsQueryable(); | |
//the ordering happens on the server and only one result will be returned. | |
mostRecentPost = q.OrderByDescending(y=>y.PostDate).FirstOrDefault(); | |
} | |
return mostRecentPost; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment