2011-12-14 64 views
2

查詢這個最好的方法是什麼? 我必須編寫一個查詢,獲取某個類型的所有文檔的計數,以及特定字段爲「xxx」的位置。我寫這在我這樣的代碼,以便 遠..查詢RavenDB的一般方法

 var store = new DocumentStore { Url = "http://localhost: 81" }; 
     store.Initialize(); 
     using (var session = store.OpenSession()) 
     { 
       //query part comes here... 
     } 
     return View(); 

展望由RavenDB樣本數據,可以說,我想編寫一個查詢 這裏獲取具有藝術家姓名專輯的文檔總數作爲「xxx」, 如何在上述代碼中執行此操作。

{ 
    "AlbumArtUrl": "/Content/Images/placeholder.gif", 
    "Genre": { 
    "Id": "genres/1", 
    "Name": "Rock" 
}, 
    "Price": 8.99, 
    "Title": "Greatest Hits", 
    "CountSold": 0, 
    "Artist": { 
    "Id": "artists/100", 
    "Name": "Lenny Kravitz" 
} 

回答

2
var store = new DocumentStore { Url = "http://localhost: 81" }; 
    store.Initialize(); 
    using (var session = store.OpenSession()) 
    { 
     int count = session.Query<Album>() 
      .Where(x => x.Artist.Name == "Lenny Kravitz") 
      .Count(); 
    } 
    return View(); 
+0

謝謝你的代碼... 無法識別..我失去了一些東西。 – ZVenue 2011-12-14 20:50:11