質問

I have an object like "Library":

public class Library
{
    List Books {get; set}
}

Book
{
    string isbn
}

I want to make an index so from a given isbn I can find the library I can't figure out how to make the map reduce.

役に立ちましたか?

解決

No reduce would be necessary to index by isbn. Think of reduce when you need aggregates (sum, count, average, min, max, etc.)

In fact, you don't even need to write the index yourself. Just let Raven do the work for you with it's dynamic index features.

var librariesContainingTheBook = session.Query<Library>()
                                 .Where(x=> x.Books.Any(y=> y.isbn == yourIsbn))

RavenDB should be able to parse this query and build the index automatically.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top