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

本文关键字:节点 属性 添加 动态 何使用 Neo4jClient | 更新日期: 2023-09-27 18:30:27

我想使用 Neo4jClient 动态添加 Lable 和 Node 的属性我尝试像以下代码一样解决它,但它不起作用。

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

我的模型是

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

我想将数据的属性导入到节点的属性中。谢谢 Z.汤姆

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

好的,首先,Neo4j默认不支持Dictionary元素(如Hashtable),因此您将需要一个自定义序列化程序,例如本问题中的序列化程序:Neo4j可以在节点中存储字典吗?

知道了这一点,您就无法按照尝试的方式设置Properties Hashtable中的值。这是不可能的

所以现在不碍事了,让我们来看看Cypher.

所以,密码明智 - 我不是 100% 确定你想做什么,我认为这样的事情是你所追求的:

var data = new Data{Type="Vegetable"};
data.Properties.Add("name", "zhai");
client.Cypher
    .Create("(person {personParam})")
    .WithParam("personParam", data)
    .ExecuteWithoutResults();

这会将节点放入数据库中,但是您将无法Properties 属性中的任何值进行查询。

我认为你应该花一点时间阅读Cypher手册,以了解你想做什么,因为我认为这会让你走得更远。