0

The official RavenDB v4 documentation suggests to use IRavenQueryable<T>.Select() method for getting custom fields in the result set. It works well even for computed fields, e.g.

session.Query<Order>()
       .Select(x => new { Total = x.Lines.Sum(l => l.PricePerUnit * l.Quantity) })

Question: Is there a way to have computed fields in the result set (like above) when using IDocumentQuery<T> or IAsyncDocumentQuery<T> instance instead of IRavenQueryable<T>?

The documentation says that the Query requests get converted into IDocumentQuery<T> under the hood. However, the closest method for narrowing down the output field set is SelectFields<T>(), which doesn't have an option for having calculated fields in the result set.

P.S. The docs say that Query is always translated into the DocumentQuery object. However, I couldn't find in the code how it's been implemented (though I guess it's done via IQueryable.Expression). Maybe RQL is a way to go now...

Alex Klaus
  • 8,168
  • 8
  • 71
  • 87
  • There is something called QueryData, see here: https://ravendb.net/docs/article-page/4.0/java/indexes/querying/projections#example-iii---projecting-arrays-and-objects It is actually documentation for java, but c# version will look the same. What's wrong with using IRvaenQueryable for such casts? – Marcin May 12 '18 at 19:37
  • @Marcin, it looks that [QueryData](https://github.com/ravendb/ravendb/blob/v4.0/src/Raven.Client/Documents/Queries/QueryData.cs) is used just for mapping static fields to serve `SelectFields()`. I'd prefer `IDocumentQuery` mostly because it's a bit easier to aggregate some common functionality via manipulating with strings rather than lambda expressions. – Alex Klaus May 14 '18 at 04:46

0 Answers0