クエリのインデックスを作成することでそれを行うことができます
public class GetOrdersByProductIndex: AbstractIndexCreationTask<Order,GetOrdersByProductIndex.Result>
{
public class Result
{
public string Product {get; set;}
}
public GetOrdersByProductIndex()
{
Map = orders => from order in orders
select new
{
Product = order.LineItems.Select(x => x.Product)
};
}
}
これで、このインデックスを使用して注文を取得できます。クエリは次のようになります
using(IDocumentSession session = docStore.OpenSession())
{
var orders = session.Query<GetOrdersByProductIndex.Result,GetOrdersByProductIndex>
.Where(x=>x.Product != "Apple")
.As<Order>()
.ToList()
}
デフォルトでは、(ravendb によって設定された制限のため) 128 レコードのみが返されることに注意してください。クエリ結果に 128 を超えるレコードがある場合は、Take(recordsNeeded)
関数を使用してデータを取得する必要があります。