2011-12-02 67 views

回答

2

NoRM MongoDB的 下面是從他們的網站的樣本:

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; 
}