Pergunta

This might be a silly question but as I'm quite new to Raven DB I'm going to dare to ask.

Imagine I have the following:

  • a Raven DB populated with a number of instances of the "EventData" object.
  • Each EventData instance has a MessageId and a timestamp.
  • the MessageId will appear twice in the list, once for when the message was sent and the other for when it was received.

So for this scenario I'd like to do a self-referential join on the table and search for the begin/end EventData pairs based on MessageId, which I could then use the Timestamp field of each to calculate the time difference between the two events.

I thought the following code would work, but I get a "Method not supported: SelectMany" error.

    var mexEvent = from startEventData in session.Query<EventData>()
                   from endEventData in session.Query<EventData>()
                   where startEventData.MessageId == endEventData.MessageId
                   select new { MessageId = startEventData.MessageId, Latency = (endEventData.EventTime - startEventData.EventTime).TotalMilliseconds };

    foreach (var eventDataItem in mexEvent)
        Console.WriteLine("MessageId: " + eventDataItem.MessageId + ", Latency: " + eventDataItem.Latency);

I need this for an internal demo so don't need it to be fancy, just functional. Can someone please help me understand how to join two documents in the same database?

Thanks!

Foi útil?

Solução

Dean, You can't do those sort of things in a query, but you can do this in a map/reduce operation very easily

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top