使用 Neo4jClient 调用 TimeTree
Calling TimeTree using Neo4jClient
我正在使用下面的代码尝试从 Neo4jClient 调用 TimeTree。
其他简单的调用都可以,但这个调用什么也不做。没有错误,但也没有新的时间对象。
public class Trip
{
public long Id { get; set; }
public string Name { get; set; }
}
public class UUID
{
public long Value { get; set; }
}
public class TimeStamp
{
//public long Id { get; set; }
//public string Name { get; set; }
public long time { get; set; }
}
public class User
{
public long Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public string Email { get; set; }
}
class Program
{
static void Main(string[] args)
{
var client = new Neo4jClient.GraphClient(new Uri("http://localhost:7474/db/data"), "neo4j", "password");
client.Connect();
client.Cypher
.Match("(n)")
.DetachDelete("n")
.ExecuteWithoutResults();
var newUser = new User { Id = 456, Name = "Jim" };
client.Cypher
.Create("(user:User {newUser})")
.WithParam("newUser", newUser)
.ExecuteWithoutResults();
var newTrip = new Trip { Id = 001, Name = "Antibes" };
client.Cypher
.Match("(traveller:User)")
.Where((User traveller) => traveller.Id == 456)
.Create("(traveller)-[:TRAVELLING]->(travelling:Trip {newTrip})")
.WithParam("newTrip", newTrip)
.ExecuteWithoutResults();
var tstamp = client.Cypher
.Match("(trip:Trip)")
.Where((Trip trip) => trip.Name == "Antibes")
.With("trip AS tripToLink")
.Call("ga.timetree.events.attach({ node: 'tripToLink', time: 1483828451000, relationshipType: \"ARRIVING_ON\"})")
.Yield("node")
.Return(node => new { TimeStamp = node.As<TimeStamp>() });
以下内容在 Shell 中有效:
MATCH (trip:Trip)
WHERE trip.Name = "Antibes"
WITH trip
CALL ga.timetree.events.attach({node: trip, time: 1483828451000 , relationshipType: "ARRIVING_ON"})
YIELD node RETURN node
首先 - 将所有代码放在那里的工作做得很好,它让生活变得更轻松!
我认为这里的问题有两个方面:您拥有的 tstamp
变量的类型为:ICypherFluentQuery<???>
(我使用“?”来表示您正在创建的匿名类型) - 所以你需要实际得到结果才能得到任何回应。在您调用 .Results
之前,您实际上并没有执行查询。
通常,我喜欢像您一样创建查询,然后在之后执行:
var tstamp = client.Cypher....
/* rest of the query here */
var tStampResults = tstamp.Results;
执行此操作时,您可能会遇到错误:
BadInputException: java.lang.String cannot be cast to org.neo4j.graphdb.Node
如果您在控制台中查看您 运行 查询的响应 - 您会发现您实际上返回了:
╒═══════════════════════════╕
│"node" │
╞═══════════════════════════╡
│{"Id":"1","Name":"Antibes"}│
└───────────────────────────┘
那是因为你正在 YIELD
ing node
,所以你只能转换为 Trip
类型:
var query = client.Cypher
.Match("(trip:Trip)")
.Where((Trip trip) => trip.Name == "Antibes")
.With("trip")
.Call("ga.timetree.events.attach({node: trip, time: 1483828451000 , relationshipType: \"ARRIVING_ON\"})")
.Yield("node")
.Return(node => node.As<Trip>()); //<-- Change here
我正在使用下面的代码尝试从 Neo4jClient 调用 TimeTree。
其他简单的调用都可以,但这个调用什么也不做。没有错误,但也没有新的时间对象。
public class Trip
{
public long Id { get; set; }
public string Name { get; set; }
}
public class UUID
{
public long Value { get; set; }
}
public class TimeStamp
{
//public long Id { get; set; }
//public string Name { get; set; }
public long time { get; set; }
}
public class User
{
public long Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public string Email { get; set; }
}
class Program
{
static void Main(string[] args)
{
var client = new Neo4jClient.GraphClient(new Uri("http://localhost:7474/db/data"), "neo4j", "password");
client.Connect();
client.Cypher
.Match("(n)")
.DetachDelete("n")
.ExecuteWithoutResults();
var newUser = new User { Id = 456, Name = "Jim" };
client.Cypher
.Create("(user:User {newUser})")
.WithParam("newUser", newUser)
.ExecuteWithoutResults();
var newTrip = new Trip { Id = 001, Name = "Antibes" };
client.Cypher
.Match("(traveller:User)")
.Where((User traveller) => traveller.Id == 456)
.Create("(traveller)-[:TRAVELLING]->(travelling:Trip {newTrip})")
.WithParam("newTrip", newTrip)
.ExecuteWithoutResults();
var tstamp = client.Cypher
.Match("(trip:Trip)")
.Where((Trip trip) => trip.Name == "Antibes")
.With("trip AS tripToLink")
.Call("ga.timetree.events.attach({ node: 'tripToLink', time: 1483828451000, relationshipType: \"ARRIVING_ON\"})")
.Yield("node")
.Return(node => new { TimeStamp = node.As<TimeStamp>() });
以下内容在 Shell 中有效:
MATCH (trip:Trip)
WHERE trip.Name = "Antibes"
WITH trip
CALL ga.timetree.events.attach({node: trip, time: 1483828451000 , relationshipType: "ARRIVING_ON"})
YIELD node RETURN node
首先 - 将所有代码放在那里的工作做得很好,它让生活变得更轻松!
我认为这里的问题有两个方面:您拥有的 tstamp
变量的类型为:ICypherFluentQuery<???>
(我使用“?”来表示您正在创建的匿名类型) - 所以你需要实际得到结果才能得到任何回应。在您调用 .Results
之前,您实际上并没有执行查询。
通常,我喜欢像您一样创建查询,然后在之后执行:
var tstamp = client.Cypher....
/* rest of the query here */
var tStampResults = tstamp.Results;
执行此操作时,您可能会遇到错误:
BadInputException: java.lang.String cannot be cast to org.neo4j.graphdb.Node
如果您在控制台中查看您 运行 查询的响应 - 您会发现您实际上返回了:
╒═══════════════════════════╕
│"node" │
╞═══════════════════════════╡
│{"Id":"1","Name":"Antibes"}│
└───────────────────────────┘
那是因为你正在 YIELD
ing node
,所以你只能转换为 Trip
类型:
var query = client.Cypher
.Match("(trip:Trip)")
.Where((Trip trip) => trip.Name == "Antibes")
.With("trip")
.Call("ga.timetree.events.attach({node: trip, time: 1483828451000 , relationshipType: \"ARRIVING_ON\"})")
.Yield("node")
.Return(node => node.As<Trip>()); //<-- Change here