The query should look like this:
var query =
_graphClient.Cypher
.Match("p=(n:Person)<-[*]-(child:Person)")
.Where((Person n) => n.name == "George")
.Return((n,p) => new descendant
{
name = n.As<Person>().Name,
depth = p.Length()
});
The Return
statement should have the 2 parameters you care about (in this case n
and p
) and project them via the lambda syntax (=>
) to create a new descendant
instance.
The main point this differs from the example, is that the example creates a new anonymous type, whereas you want to create a concrete type.
We then use the property initializer (code inside the { }
braces) to set the name and depth, using the As<>
and Length
extension methods to get the values you want.
As a side note, I've also changed the Where
clause to use parameters, you should always do this if you can, it will make your queries both faster and safer.