Node <t> </t>的默认节点类型

时间:2013-10-14 14:08:56

标签: neo4jclient

我开始研究使用neo4client API来使用Neo4j。 我创建了一个基本数据库,可以使用Web客户端进行查询。我现在正在尝试构建一个示例C#接口。我在索引查找方面遇到了一些问题。我的数据库由具有两个属性的节点组成:conceptID和fullySpecifiedName。启用了自动索引,两个节点属性都列在neo4j.properties的node_keys_indexable属性中。

使用Node类时,我在C#中不断收到IntelliSense错误。它似乎被定义为Node<T>,但我不知道该提供什么作为该类型的值。从这个论坛考虑这个例子......

var result = _graphClient
.Cypher
.Start(new
{
    n = Node.ByIndexLookup("index_name", "key_name", "Key_value")
})
.Return((n) => new
{
    N = n.Node<Item>()
})
.Results
.Single();

var n = result.N;

Node<Item>中的“项目”来自哪里? 我推断出我应该使用的索引名称是node_auto_index,但我无法找出默认的节点类型。

1 个答案:

答案 0 :(得分:1)

Item是您存储在数据库中的节点类型,因此,如果您要存储类:

public class MyType { public int conceptId { get; set; } public string fullySpecifiedName { get;set; } }

您将检索Node<MyType>

简单流程:

//Store a 'MyType'
_graphClient.Create(new MyType{conceptId = 1, fullySpecifiedName = "Name");

//Query MyType by Index
var query = 
    _graphClient.Cypher
        .Start(new { n = Node.ByIndexLookup("node_auto_index", "conceptId", 1)
        .Return<Node<MyType>>("n");

Node<MyType> result = query.Results.Single();

//Get the MyType instance
MyType myType = result.Data;

您可以通过result.Data代替.Return<MyType>("n")来绕过Node<MyType>步骤,因为在这种情况下您只会获得MyType的实例。