1

试图在这样的查询中查看关系:

var query = _graph.Cypher.Start(
new
{
    me = Node.ByIndexLookup("node_auto_index", "id", p.id)
}).Match("me-[r:FRIENDS_WITH]-friend")
.Where((Person friend) => friend.id == f.id)
.Return<FriendsWith>("r");

这是 FriendsWith 类。我无法为 FriendsWith 添加无参数构造函数,因为基类 (Relationship) 没有无参数构造函数。

public class FriendsWith : Relationship,
        IRelationshipAllowingSourceNode<Person>,
        IRelationshipAllowingTargetNode<Person>
    {
        public FriendsWith(NodeReference<Person> targetNode)
            : base(targetNode)
        {
            __created = DateTime.Now.ToString("o");
        }
        public const string TypeKey = "FRIENDS_WITH";
        public string __created { get; set; }
        public override string RelationshipTypeKey
        {
            get { return TypeKey; }
        }

    }

但我收到错误“没有为此对象定义无参数构造函数”。当我尝试运行它时。返回查询关系的正确方法是什么?

堆栈跟踪

在 Neo4jClient.Deserializer.CypherJsonDeserializer 1.Deserialize(String content) in c:\TeamCity\buildAgent\work\f1c4cf3efbf1b05e\Neo4jClient\Deserializer\CypherJsonDeserializer.cs:line 53 at Neo4jClient.GraphClient.<>c__DisplayClass1d1.b__1c(任务1 responseTask) in c:\TeamCity\buildAgent\work\f1c4cf3efbf1b05e\Neo4jClient\GraphClient.cs:line 793 at System.Threading.Tasks.ContinuationResultTaskFromResultTask2.InnerInvoke() 在 System.Threading.Tasks.Task.Execute()

4

1 回答 1

0

只需将其反序列化为代表数据结构的 POCO:

public class FriendsWith
{
    public string __created { get; set; }
}

var query = _graph.Cypher
    .Start(new {
        me = Node.ByIndexLookup("node_auto_index", "id", p.id)
    })
    .Match("me-[r:FRIENDS_WITH]-friend")
    .Where((Person friend) => friend.id == f.id)
    .Return(r => r.As<FriendsWith>())
    .Results;

你实际上根本不需要这FriendsWith : Relationship, IRelationshipAllowingSourceNode<Person>, IRelationshipAllowingTargetNode<Person>门课。

使用 Cypher 创建关系:

_graph.Cypher
    .Start(new {
        me = Node.ByIndexLookup("node_auto_index", "id", p.id),
        friend = Node.ByIndexLookup("node_auto_index", "id", p.id + 1)
    })
    .CreateUnique("me-[:FRIENDS_WITH {data}]->friend")
    .WithParams(new { data = new FriendsWith { __created = DateTime.Now.ToString("o") } })
    .ExecuteWithoutResults();

您将在 Neo4jClient wiki 上看到更多示例。基本上,在这个时代,一切都应该是 Cypher。

于 2013-10-25T23:04:32.573 回答