2011-12-14 63 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