2
votes

I've started using RavenDB with C# project. I have documents with structure:

{
  "MessageId": "8c34dec8-e6fe-6bee-2dc6-2cf83e374090",
  "Headers": {
    "Header.MessageId": "14f6cdf3-142d-4ab0-9610-a65600f1f460",
    "Header.Timestamp": "2016-08-02 12:40:55:783130 Z",
    "$.diagnostics.host": "1ddc6cefd4d776f1de8fefc33a45d020",
  },
  "Timestamp": "2016-08-02T12:43:25.3914940Z"
}

I can get document by MessageId:

var doc = session.Query<Messages>().Where(w => w.MessageId == "8c34dec8-e6fe-6bee-2dc6-2cf83e374090").ToList();

But I want to get document by: Headers.Header.MessageId. Unfortunately in Headers there are keys with prefix (Header and $) and I don't know how to handle it in session.Query<Messages>() statement.

I can do it in RavenDB Studio:

from doc in docs.Messages
where doc.Headers["Header.MessageId"] == "14f6cdf3-142d-4ab0-9610-a65600f1f460"
select new { 
    Id = doc.MessageId,
    MessageId = doc.Headers["Header.MessageId"]
}

I tried to create Lucene query but it's not working:

var doc = session.Advanced.LuceneQuery<object>().WhereEquals("Headers.Header.MessageId", "14f6cdf3-142d-4ab0-9610-a65600f1f460").ToList();

Can you tell me what I'm doing wrong and help me please?

1
i am facing same issue, whats the solution to select key with dot(.). In my case it always return null value while using doc.MessageId & return error message in case of doc.Headers["Header.MessageId"]. - nirav

1 Answers

0
votes

are your docs created with the management? because your doc can't be represented in a .net class (also by Messages) (you can't have a property name with dot), this means that you can't load the doc; you need to patch the docs (to remove the dot)