1

I want to add Lable and properties of Node dynamically using Neo4jClient I try to solve it like following code,but it doesn't work.

        client.Cypher
                 .Create("(person:Type)")
                 .WithParam("Type", "Vegetable")
                 .Set("person.property= \"zhai\"")
                 .WithParam("property", "name")
                 .ExecuteWithoutResults();

my Model is

class Data
{
        public Data()
        {
            properties = new Hashtable();
        }

        private string type;

        public string Type
        {
            get { return type; }
            set { type = value; }
        }

        private Hashtable properties;

        public Hashtable Properties
        {
            get { return properties; }
            set { properties = value; }
        }

    }

I want to import the properties of Data into properties of node. Thx Z.Tom

Z.Tom
  • 37
  • 6

1 Answers1

0

OK, first off, Neo4j doesn't support Dictionary elements (like a Hashtable) by default so you're going to need a custom serializer, such as the one in this question: Can Neo4j store a dictionary in a node?

Knowing this, you can't set the values in the Properties Hashtable the way you are trying to. It's not possible.

So now that's out of the way, let's have a look at the Cypher.

So, cypher wise - I'm not 100% sure what you're trying to do, BUT I think something like this is what you're after:

var data = new Data{Type="Vegetable"};
data.Properties.Add("name", "zhai");

client.Cypher
    .Create("(person {personParam})")
    .WithParam("personParam", data)
    .ExecuteWithoutResults();

That will put the node into the database, however you will not be able to query by any value in the Properties property.

I think you should spend a bit of time reading the Cypher manual to understand what it is you're trying to do, as I think that will get you a lot further.

Community
  • 1
  • 1
Charlotte Skardon
  • 6,220
  • 2
  • 31
  • 42