Neo4j 客户端 UNWIND 与“DateTime?" [英] Neo4j Client UNWIND with "DateTime?"

查看:68
本文介绍了Neo4j 客户端 UNWIND 与“DateTime?"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm currently trying to unwind a list of TravelEdges that has a "DateTime?" but I keep receiving the following error:

{"CypherTypeException: 类型不匹配:需要一个地图,但是是 String(\"2018-05-21T08:38:00\")"}

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

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

I'm currently using the latest version of neo4j (3.4.8) and was wondering if someone could assist?

另外,有没有更有效的方法可以在没有两个匹配的情况下添加边缘?Id 是唯一的.

Also, is there a more efficient way of adding the edges without having two matches? The Id's are unique.

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;}
}

推荐答案

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

@cypbersam is correct regarding your second query, but your sc is a map, as your TravelEdge class is treated as a map by the DB.

我几乎逐字地获取了代码(见下文),当我使用 GraphClientBoltGraphClient 运行它时,它对我来说完全正常.所以,我想这可能是 Neo4jClient 版本的问题 - 你使用的是什么版本?

I've taken the code pretty much verbatim (see below) and when I run it with the GraphClient or the BoltGraphClient it works totally fine for me. So, I guess this could be a problem with the version of Neo4jClient - what version are you using?

复制/粘贴时要小心,我在前几行中完全删除了数据库

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;}
}

这篇关于Neo4j 客户端 UNWIND 与“DateTime?"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆