Neo4j 客户端 UNWIND "DateTime?"

Neo4j Client UNWIND with "DateTime?"

我目前正在尝试展开具有 "DateTime?" 的 TravelEdges 列表,但我不断收到以下错误:

{"CypherTypeException: Type mismatch: expected a map but was String(\"2018-05-21T08:38:00\")"}

我目前使用的是最新版本的 neo4j (3.4.8),想知道是否有人可以提供帮助?

此外,有没有更有效的方法来添加边缘而不需要两个匹配项? Id 是唯一的。

List<TravelEdge> travelpoints = new List<TravelEdge>();

//Add stuff to list

graphClient.Cypher
.Unwind(travelpoints, "sc")
.Match("(s1:Node { Id: sc.Id1})")
.Match("(s2:Node { Id: sc.Id2})")
.Merge("(s1)-[t:Travels_To]->(s2)")
.OnCreate()
.Set("t.Time = sc.TravelTime")
.ExecuteWithoutResults();


public class Node{

//Unique
public long Id {get;set;}

}

public class Edge {

public DateTime? TravelTime {get;set;}

}

public class TravelEdge{

public long Id1 {get;set;}

public long Id2 {get;set;}

public DateTime? TravelTime {get;set;}
}
  1. 每个 sc 值都是一个字符串,但您的查询正试图将其用作地图。也就是说,当 sc 是字符串而不是映射时,sc.Id1sc.Id2 没有任何意义。您需要更改 travelpoints 值,使其成为具有 Id1Id2 值的地图列表。

  2. 如果不查找这些节点,则无法确保 t:Travels_To 关系存在于 2 个特定节点之间。但是,为了帮助加快查找速度,您可以在 :Node(Id).

  3. 上创建一个 index or uniqueness constraint

@cypbersam 关于您的第二个查询是正确的,但是您的 sc 一个 map,因为您的 TravelEdge class 被数据库视为 map

我几乎逐字记录了代码(见下文),当我 运行 使用 GraphClientBoltGraphClient 时,它对我来说完全没问题。所以,我想这可能是 Neo4jClient 版本的问题 - 您使用的是什么版本?

下面的工作代码

小心复制/粘贴,我把前几行的DB全删了

void Main()
{
    //var graphClient = new GraphClient(new Uri("http://localhost:7474/db/data"), "neo4j", "neo");
    var graphClient = new BoltGraphClient("bolt://localhost:7687", "neo4j", "neo");
    graphClient.Connect();

    graphClient.Cypher.Match("(n)").DetachDelete("n").ExecuteWithoutResults();

    List<TravelEdge> travelpoints = new List<TravelEdge>{
        new TravelEdge { Id1 = 1, Id2 = 2, TravelTime = new DateTime(2000,1,1) },
        new TravelEdge { Id1 = 2, Id2 = 3, TravelTime = new DateTime(2000,1,2) },
        new TravelEdge { Id1 = 3, Id2 = 4, TravelTime = new DateTime(2000,1,3) },
        new TravelEdge { Id1 = 4, Id2 = 5, TravelTime = null },
    };

    var ids = new [] {1,2,3,4,5};
    graphClient.Cypher
        .Unwind(ids, "id")
        .Merge("(a:Node {Id: id})")
        .ExecuteWithoutResults();



    //Add stuff to list
    graphClient.Cypher
        .Unwind(travelpoints, "sc")
        .Match("(s1:Node { Id: sc.Id1})")
        .Match("(s2:Node { Id: sc.Id2})")
        .Merge("(s1)-[t:Travels_To]->(s2)")
        .OnCreate()
        .Set("t.Time = sc.TravelTime")
        .ExecuteWithoutResults();
}


public class Node{
    public long Id {get;set;}
}

public class TravelEdge {
    public long Id1 {get;set;}
    public long Id2 {get;set;}
    public DateTime? TravelTime {get;set;}
}