You can't do that in RavenDB - the field you're querying must be on the left of the predicate, and the right of the predicate cannot refer to another field.
As for how to restructure this - Sorry, not sure.
Edit:
Okay, it took some experimentation - but I managed to make it work IF it's possible to either restructure MaterializedPath, or add a new property. I'll assume here it's a new property, to avoid any confusion.
// Sample class:
public class Item
{
public string Name { get;set;}
public Dictionary<int, string> Path { get;set;} // Zero-based key on path.
}
// Query: Find nodes with path "A B"
var query = session.Query<Item>().AsQueryable();
query = query.Where(item => item.Path[0] == "A");
query = query.Where(item => item.Path[1] == "B");
var found = query.ToList();
And here it is running:
IDocumentStore store = new EmbeddableDocumentStore { RunInMemory = true };
store.Initialize();
// Install Data
using (var session = store.OpenSession())
{
session.Store(new Item("Foo1", "A")); // NB: I have a constructor on Item which takes the path and splits it up. See below.
session.Store(new Item("Foo2", "A B"));
session.Store(new Item("Foo3", "A C D"));
session.Store(new Item("Foo4", "A B C D"));
session.Store(new Item("Foo5", "C B A"));
session.SaveChanges();
}
using (var session = store.OpenSession())
{
var query = session
.Query<Item>().AsQueryable();
query = query.Where(item => item.Path[0] == "A");
query = query.Where(item => item.Path[1] == "B");
var found = query.ToList();
Console.WriteLine("Found Items: {0}", found.Count );
foreach(var item in found)
{
Console.WriteLine("Item Name {0}, Path = {1}", item.Name, string.Join(" ", item.Path));
}
}
The output from this is:
Found Items: 2
Item Name Foo2, Path = [0, A] [1, B]
Item Name Foo4, Path = [0, A] [1, B] [2, C] [3, D]
Hope that helps.
Edit 2:
The constructor I have on Item looks like this, just for ease of testing:
public Item(string name, string materializedPath)
{
Name = name;
var tmpPath = materializedPath.Split(' ');
Path =
tmpPath
.Zip(Enumerable.Range(0, tmpPath.Count()), (item, index) => new {Item = item, Index = index})
.ToDictionary(k => k.Index, v => v.Item);
}