简体   繁体   English

如何使用 C# 中的 Neo4j.Driver 从 Neo4j 记录中检索标签

[英]How can i retrieve the label from a Neo4j record using the Neo4j.Driver in C#

I am using the Neo4j.Driver in C# to query a Neo4J database.我在 C# 中使用 Neo4j.Driver 来查询 Neo4J 数据库。 My cypher query returns multiple nodes that don't have the same label, lets say i return both movies and actors.我的密码查询返回多个没有相同标签的节点,假设我同时返回电影和演员。 I have a C# Movie and a C# Actor class.我有一个 C# 电影和一个 C# 演员类。 In order to instantiate the proper C# class (either movie or actor) and set the properties based on the returned records, how do i find out what label(s) a returned node has?为了实例化正确的 C# 类(电影或演员)并根据返回的记录设置属性,我如何找出返回的节点具有什么标签?

var cursor =  await transaction.RunAsync(cypher.ToString());
            await cursor.ForEachAsync(record =>
            {
                var movie = new Movie();
                movie.Name = record["name"].As<string>();
                ....
            }

On a Node object you should find the Labels property, @see https://github.com/neo4j/neo4j-dotnet-driver/blob/7d954b4d86d134b360a8889ff14a2b6b1a339d7f/Neo4j.Driver/Neo4j.Driver/Types/INode.cs#L31Node对象上,您应该找到Labels属性,@see https://github.com/neo4j/neo4j-dotnet-driver/blob/7d954b4d86d134b360a8889ff14a2b6b1a339d7f/Neo4j.Driver/Neo4j.NodeIr.cs#

As an example :举个例子 :

var cursor =  await transaction.RunAsync(cypher.ToString());
await cursor.ForEachAsync(record =>
{
  var movie = new Movie();
  movieNode = record["movie"].As<INode>();
  movieNode.Labels[0]
  ....
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM