c# - Neo4jClient 不向关系添加属性

标签 c# neo4j neo4jclient

我们一直在尝试编写一个 C# 客户端来为 Neo4j 实例播种一些节点和关系。我们在尝试创建关系属性时面临问题。

这是创建与标志属性的关系的代码:

var s = clientConnection.CreateRelationship(root, new RelationshipPrincipleToContent("SECURITY", rootFolder) { flags = "+W" });

这是关系类:

public class RelationshipPrincipleToContent : Relationship, IRelationshipAllowingSourceNode<Principles>, IRelationshipAllowingTargetNode<Content>{
    public string flags { get; set; }
    string RelationshipName;

    public RelationshipPrincipleToContent(NodeReference targetNode) : base(targetNode){}

    public RelationshipPrincipleToContent(string RelationshipName, NodeReference targetNode): base(targetNode){
        this.RelationshipName = RelationshipName;
    }

    public override string RelationshipTypeKey{
        get { return RelationshipName; }
    }
}

当我们在数据浏览器选项卡中查看数据时,没有关于关系的属性。我们还创建了一个关系索引?

我们错过了什么/做错了什么?

最佳答案

首先添加一个类(在本例中为 PayLoad.cs),该类包含一组公共(public)字符串。

 public class PayLoad
    {
        public string Comment { get; set; }
    }

更新您的关系类以使用此 PayLoad 类:

public class RelationshipPrincipleToContent : Relationship<PayLoad>, IRelationshipAllowingSourceNode<Principles>, IRelationshipAllowingTargetNode<Content>
    {
        string RelationshipName;

        public RelationshipPrincipleToContent(string RelationshipName, NodeReference targetNode, PayLoad pl)
            : base(targetNode, pl)
        {
            this.RelationshipName = RelationshipName;
        }

        public override string RelationshipTypeKey
        {
            get { return RelationshipName; }
        }
    }
}

现在只需更新您对关系类的方法调用:

clientConnection.CreateRelationship(AllPrincipals, new RelationshipPrincipleToContent("SECURITY", rootFolder, new PayLoad() { Comment = "+R" }));

关于c# - Neo4jClient 不向关系添加属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18719900/

相关文章:

c# 使用爱普生热敏打印机打印长收据

neo4j - 从图形中获取文本格式的路径

neo4j - 如何使用neo4j在树中找到根 parent ?

c# - Neo4j 客户端匹配 Id 列表

c# - 多次使用 "from"是否等同于加入?

C# WPF Modern UI 禁用或隐藏 LinkGroup

c# - 使用 SQLiteAsyncConnection 在 SQLite-net C# 中创建通用查询

neo4j - Cypher 排除关系

c# - .NET - neo4jclient - 从密码查询中检索结果

Neo4j数据库添加关系非常慢