简体   繁体   English

如何使用Neo4jClient动态添加节点属性?

[英]How to add properties of node dynamically using Neo4jClient?

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. 我想使用Neo4jClient动态添加Lable和Node的属性,我尝试像下面的代码一样解决它,但是它不起作用。

        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 汤姆·汤姆

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? 好的,首先, Neo4j默认情况下不支持Dictionary元素(如Hashtable ),因此您将需要一个自定义的序列化程序,例如该问题中的一个: Neo4j可以在节点中存储字典吗?

Knowing this, you can't set the values in the Properties Hashtable the way you are trying to. 知道这一点后,您将无法按照尝试的方式在“ Properties Hashtable ”中设置值。 It's not possible. 这是不可能的。

So now that's out of the way, let's have a look at the Cypher . 因此,现在已经不成问题了,让我们看一下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: 因此,在密码方面明智-我不是100%知道您要做什么, 但是我认为您追求的是这样的事情:

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. 这样会将节点放入数据库中, 但是您将无法通过Properties属性中的任何值进行查询。

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. 我认为您应该花一些时间阅读Cypher手册,以了解您要执行的操作,因为我认为这将使您更进一步。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM