首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Neo4jClient -查询关系

Neo4jClient -查询关系
EN

Stack Overflow用户
提问于 2013-05-08 13:04:28
回答 1查看 302关注 0票数 1

尝试查看如下查询中的关系:

代码语言:javascript
复制
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添加无参数构造函数,因为基类(关系)没有无参数构造函数。

代码语言:javascript
复制
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; }
        }

    }

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

堆栈跟踪

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

EN

回答 1

Stack Overflow用户

发布于 2013-10-26 07:04:33

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

代码语言:javascript
复制
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创建关系:

代码语言:javascript
复制
_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维基上看到更多示例。基本上,在这个时代,一切都应该是Cypher。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16433030

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档