1

I have a RavenDB query using index and I need to add condition checking nested objects type (these objects aren't separate documents)

entries = session.Query<result, index>()
  /* some conditions here */
  .Where(x => x.Messages.Any(m => m.GetType() == typeof(MyMessage)))
  .ToList();

Raven tells me, that he doesn't know how to translate GetType. So how can I achieve this?

Sarrus
  • 586
  • 7
  • 21
  • Does `MyMessage` have a property you could query for a predictable value? – Brian Jun 27 '14 at 15:56
  • No. We have different message types for template choose. This is the problem - all massages have the same set of properties. – Sarrus Jun 30 '14 at 07:08

1 Answers1

5

After long research I found the solution.

I added field to index:

MessageTypes = entry.Messages.Select(m => AsDocument(m)["$type"].ToString())

AsDocument() returns RavenJObject which contains all properties including $type. With that property indexed, asking for certain type is quite simple

Sarrus
  • 586
  • 7
  • 21