Neo4j如何返回节点和关系?

时间:2013-05-26 12:30:03

标签: neo4j neo4jclient

我正在使用Neo4jClient来编写演示。我的演示有两个节点: Beer BeerBrand ,一个关系Is_Made有属性ReleaseDay 。我编写了这段代码来获取节点 BeerBrand ,它们制作了特定的啤酒。

var isMadeBy = beer
                .StartCypher("b")
                .Match("b-[r:IS_MADE]->e")
                .Return<Node<BeerBrand>>("e")                
                .Results.ToList();

现在,我想得到关系* Is_Made *

var isMadeBy = beer
                .StartCypher("b")
                .Match("b-[r:IS_MADE]->e")
                 .Return<Relationship<IsMade>>("r")
                .Results.ToList();

但是,错误被抛出

class IsMade must be non-abstract type with a public parameterless constructor 
in order to use it as parameters 'TData' in the generic type or 
method 'Neo4jClient.Relationship<TData>'

你能帮我解决这个问题吗?

2 个答案:

答案 0 :(得分:0)

你看过维基吗? http://hg.readify.net/neo4jclient/wiki/cypher

如果您不需要关系ID,请尝试尝试:

var isMadeBy = beer
     .StartCypher("b")
     .Match("b-[r:IS_MADE]->e")
     .Return((r, e) => new {
          isMadeRelationship = r.As<Node<SomeObjectWithAPublicConstructor>>()
          beerBrand = e.As<Node<BeerBrand>>()
      })
      .Results.ToList();

答案 1 :(得分:0)

这里有一个类似问题的答案:Neo4jClient - Retrieving relationship from Cypher query它将为您提供您应该遵循的指南。

本质上,您需要在关系中添加一个无参数构造函数,以允许客户端(特别是JSON.NET)能够将您的关系从数据库中的内容反序列化到您的代码。基本上--JSON.NET无法弄清楚如何构建你的关系,因为它不知道你的构造函数中的参数是什么。

您可能还需要从返回'Relationship'更改为'RelationshipInstance'。

相关问题