Saa*_*ooq 5 c# shortest-path neo4j graph-databases neo4jclient
我有以下Cypher Query,它在Neo4j 2.0.0中运行良好.
MATCH (ab:Point { Latitude: 24.96325, Longitude: 67.11343 }),(cd:Point { Latitude: 24.95873, Longitude: 67.10335 }),
p = shortestPath((ab)-[*..150]-(cd))
RETURN p
Run Code Online (Sandbox Code Playgroud)
Neo4jClient中的以下查询给出错误:功能评估超时.
var pathsQuery =
client.Cypher
.Match("(ab:Point { Latitude: 24.96325, Longitude: 67.11343 }),(cd:Point { Latitude: 24.95873, Longitude: 67.10335 }), p = shortestPath((ab)-[*..150]-(cd))")
.Return<IEnumerable<PointEntity>>("extract(n in nodes(p) : id(n))");
Run Code Online (Sandbox Code Playgroud)
和之后关于Xclave的另一个类似的工作:
http://geekswithblogs.net/cskardon/archive/2013/07/23/neo4jclient-ndash-getting-path-results.aspx
结果值为:功能评估超时.
var pathsQuery =
client.Cypher
.Match("(ab:Point { Latitude: 24.96325, Longitude: 67.11343 }),(cd:Point { Latitude: 24.95873, Longitude: 67.10335 }), p = shortestPath((ab)-[*..150]-(cd))")
.Return(p => new PathsResult<PointEntity>
{
Nodes = Return.As<IEnumerable<Node<PointEntity>>>("nodes(p)"),
});
Run Code Online (Sandbox Code Playgroud)
如何在C#中将查询返回的所有节点作为PointEntity类型列表?
编辑:
我能够从这段代码中获取节点和关系的URI:
var pathsQuery =
client.Cypher
.Match("(ab:Point { Latitude: 24.96325, Longitude: 67.11343 }),(cd:Point { Latitude: 24.95873, Longitude: 67.10335 }), p = shortestPath((ab)-[*..150]-(cd))")
var results = pathsQuery.Return<PathsResult>("p").Results;
Run Code Online (Sandbox Code Playgroud)
关注Craig Brett的博客:http: //craigbrettdevden.blogspot.co.uk/2013/03/retrieving-paths-in-neo4jclient.html
我试图获得POCO但却出错了:
var paths = pathsQuery.Returns<PathsResult>("EXTRACT(n in nodes(p) : n) AS Nodes, EXTRACT(rel in rels(p) : rel) AS Relationships", CypherResultMode.Projection).Results;
Run Code Online (Sandbox Code Playgroud)
错误:
'Neo4jClient.Cypher.ICypherFluentQuery' does not contain a definition for 'Returns' and no extension method 'Returns' accepting a first argument of type 'Neo4jClient.Cypher.ICypherFluentQuery' could be found (are you missing a using directive or an assembly reference?)
Run Code Online (Sandbox Code Playgroud)
我不能说为什么第一个查询不起作用,我现在无法测试,因为我的Neo4j版本不允许我在我的MATCH子句中使用参数.但是 - 我确实得到了我的版本(下面)很好.就超时而言,这[*..150]是一个相当大的潜在遍历.
你可以尝试跑步:
var pathsQuery =
Client.Cypher
.Match("p = shortestPath((ab:Point)-[*..150]-(cd:Point))")
.Where((PointEntity ab) => ab.Latitude == 24.96325)
.AndWhere((PointEntity ab) => ab.Longitude == 67.11343)
.AndWhere((PointEntity cd) => cd.Latitude == 24.95873)
.AndWhere((PointEntity cd) => cd.Longitude == 67.10335)
.Return(p => new PathsResult<PointEntity>
{
Nodes = Return.As<IEnumerable<Node<PointEntity>>>("nodes(p)"),
Relationships = Return.As<IEnumerable<RelationshipInstance<object>>>("rels(p)")
});
var res = pathsQuery.Results;
Run Code Online (Sandbox Code Playgroud)
在哪里PathsResult定义为:
public class PathsResult<TNode>
{
public IEnumerable<Node<TNode>> Nodes { get; set; }
public IEnumerable<RelationshipInstance<object>> Relationships { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
这里的好处是WHERE条款是绝对的.