ZVenue
ZVenue

Reputation: 5027

General method of querying RavenDB

Whats the best way to query this. I have to write a query that gets Count of all documents of a certain type and where a particular field is "xxx". I am writing this in my code like this so far..

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

Going by sample date in RavenDB, lets say, I want to write a query here that gets total number of Album documents that have Artist name as "xxx" how do I do that in the above code.

{ 
  "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" 
} 

Upvotes: 2

Views: 277

Answers (1)

Daniel Lang
Daniel Lang

Reputation: 6839

    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(); 

Upvotes: 2

Related Questions