1

I have a pretty simple index that returns a flattened structure of Products and here is how I use it:

_documentSession.Query<ProductsIndex.IndexResult, ProductsIndex>().
  Customize(x => x.WaitForNonStaleResults()).
  OrderByDescending(x => x.DateTime).
  Take(20).
  AsProjection<ProductsIndex.IndexResult>().
  ToList();

It works and returns 20 last results. Now I want to add a transformer to this query. Here is my try:

_documentSession.Query<ProductsIndex.IndexResult, ProductsIndex>().
  Customize(x => x.WaitForNonStaleResults()).
  TransformWith<ProductsTransformer, ProductsTransformer.TransformerResult>().
  OrderByDescending(x => x.DateTime).
  Take(20).
  AsProjection<ProductsTransformer.TransformerResult>().
  ToList();

So I added TransformWith line and changed AsProjection line. The problem is it returns only 8 documents. As I understand it doesn't get the AsProjection part and returns the Products themselves.

SiberianGuy
  • 24,674
  • 56
  • 152
  • 266

1 Answers1

2

You need to use:

_documentSession.Query<ProductsIndex.IndexResult, ProductsIndex>().
  Customize(x => x.WaitForNonStaleResults().SetAllowMultipleIndexEntriesForSameDocumentToResultTransformer(true)).
  TransformWith<ProductsTransformer, ProductsTransformer.TransformerResult>().
  OrderByDescending(x => x.DateTime).
  Take(20).

ToList();

Note the SetAllowMultipleIndexEntriesForSameDocumentToResultTransformer call

Ayende Rahien
  • 22,925
  • 1
  • 36
  • 41
  • 1
    Thanks, it helped. Would be great to have it here: http://ravendb.net/docs/2.5/client-api/querying/results-transformation/result-transformers – SiberianGuy Aug 06 '14 at 11:21