0
votes

I am trying to use Neo4jClient (and am new to C#) to build and retrieve data from Neo4j. First, I build the items and relations to a search:

 NodeReference<Search> searchNode = client.Create(searches[i]);

    itmNode = client.Create(items[j], new IRelationshipAllowingParticipantNode<Item>[0],
              new[]
             {
               new IndexEntry("Item")
              {
                     {"Type", items[j].Type },
                     {"ItemDescription", items[j].ItemDescription },
                     {"ItemNumber", items[j].ItemNumber }
               }
            });
client.CreateRelationship(itmNode, new SearchedFor(searchNode, 1));

Then, I am testing the retrieval of the node back from Neo4j:

var results = client.Cypher.Start("n", itemDict[firstitem])
                .Match("n-[r]->()<-[r2]-other")
                .Return<Node<Item>>("other")
                .Results;

var node6 = ((IRawGraphClient)client).ExecuteGetCypherResults<Node<Item>>(new Neo4jClient.Cypher.CypherQuery("start n=node(6) return n;", null,Neo4jClient.Cypher.CypherResultMode.Set)).Select(un => un.Data);

"results" returns the 2 nodes that are related to node(6). "node6" is other code I found that I thought would return node 6. Both of these return the nodes, but the properties returned are all blank. I can see the properties in the Neo4j Monitoring Tool, but not when they are returned using Neo4jClient. Am I missing something in how I am setting up the nodes, or on how I am retrieving the data?

My object return shows Data.ItemDescription="", Data.ItemNumber=0, Reference=Node 5

Adding the "Select(un => un.Data)" after .Results did not work like I saw in other examples like this

Please let me know if you need more information.

Neo4jClient version 1.0.0.579

Neo4j version 1.8.2

Here is the item class:

 public class Item
    {
        private string _name;
        private string _desc;
        private long _id;

        public Item(string name, string desc, long id)
        {
            _name = name;
            _desc = desc;
            _id = id;
        }

        public Item()
        {
            _name = "";
            _desc = "";
            _id = 0;
        }

        public long ItemNumber
        {
            get
            {
                return _id;
            }
        }

        public string ItemDescription
        {
            get
            {
                return _desc;
            }
        }
        public string Type
        {
            get
            {
                return "Item";
            }
        }
    }
1
Can you add the class definition for "Item"?Tatham Oddie
@TathamOddie - I have added the "Item" class definition.pgmLiz

1 Answers

1
votes

Making it work

The issue is that your Item class has no setters exposed. There's no way for us to set those properties , so we ignore them.

You can delete half your code, and it'll work. :)

public class Item
{
    public long ItemNumber { get; set; }
    public string ItemDescription { get; set; }
    public string Type { get ; set; }
}

Making it better

Replace this:

NodeReference<Search> searchNode = client.Create(searches[i]);

    itmNode = client.Create(items[j], new IRelationshipAllowingParticipantNode<Item>[0],
              new[]
             {
               new IndexEntry("Item")
              {
                     {"Type", items[j].Type },
                     {"ItemDescription", items[j].ItemDescription },
                     {"ItemNumber", items[j].ItemNumber }
               }
            });
client.CreateRelationship(itmNode, new SearchedFor(searchNode, 1));

with this:

var searchNode = client.Create(searches[i]);

var itemNode = client.Create(
    items[j],
    new[] { new SearchedFor(searchNode, 1) }
    new[]
    {
        new IndexEntry("Item")
        {
            {"Type", items[j].Type },
            {"ItemDescription", items[j].ItemDescription },
            {"ItemNumber", items[j].ItemNumber }
        }
    });

That will create that second node, and the relationship, in a single call.