0

I'm using the code below in an attempt to Call TimeTree from Neo4jClient.

Other simple Calls work, but this one just does nothing. No errors, but also no new time object.

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

The following does work in the 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
Opononi
  • 133
  • 1
  • 6

1 Answers1

1

First off - good work on putting all the code there, it made life a lot easier!

I believe the problem here is two fold: the tstamp variable you have is of type: ICypherFluentQuery<???> (I'm using '?' to represent the anonymous type you're creating) - so you need to actually get the results to get any response. Until you call .Results you don't actually execute the query.

Typically, I like to create the query as you have and then execute after:

var tstamp = client.Cypher....
    /* rest of the query here */

var tStampResults = tstamp.Results;

When you do this you'll probably get an error:

BadInputException: java.lang.String cannot be cast to org.neo4j.graphdb.Node

If you look at your response from the query you run in the console - you'll see you actually get back:

╒═══════════════════════════╕
│"node"                     │
╞═══════════════════════════╡
│{"Id":"1","Name":"Antibes"}│
└───────────────────────────┘

and that's because you are YIELDing node, so you'll only be able to cast to Trip type:

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
Charlotte Skardon
  • 6,220
  • 2
  • 31
  • 42
  • Thanks @Chris Skardon. On a side note, we recommend using automatic event attachments which would make manual process disappear : https://github.com/graphaware/neo4j-timetree#automatic-event-attachment – Christophe Willemsen Jan 10 '17 at 16:17
  • Thanks, I've made the suggested changes, but still getting "{"BadInputException: java.lang.String cannot be cast to org.neo4j.graphdb.Node"}" error on the "var tStampResults = tstamp.Results;" line – Opononi Jan 11 '17 at 11:45
  • Have you copied the code I've put there and run that? I'm running the code copy/pasted and it's working perfectly, can you add your changed code to your question? – Charlotte Skardon Jan 11 '17 at 14:13