Skip to content

Instantly share code, notes, and snippets.

@abolibibelot
Forked from atheken/LINQ-to-MongoDB.cs
Created July 12, 2010 14:17
Show Gist options
  • Save abolibibelot/472513 to your computer and use it in GitHub Desktop.
Save abolibibelot/472513 to your computer and use it in GitHub Desktop.
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