Build a dynamic query using neo4j client

自闭症网瘾萝莉.ら 提交于 2020-01-06 02:58:06

问题


I read many questions on this topic and created the following almost dynamic query:

var resQuery = WebApiConfig.GraphClient.Cypher
                .Match("(movie:Movie {title:{title}})")
                .WithParam("title", title)
                .Return(() => new {
                    movie = Return.As<string>("movie.title")
                }).Results;

Unfortunately this isn't dynamic since I'm declaring the movie property in the Return anonymous type.

In all the examples I found the only option is to return the nodes as an object matches the node properties, like: movie = Return.As<string>("movie.title")

I want the Return statement to give me back a key-value pair list of all the node properties (it can be in any representation like JSON etc..), since my nodes are generic and not from a specific object kind every time.

is that possible?


回答1:


You can do something like this:

var resQuery = WebApiConfig.GraphClient.Cypher
    .Match("(movie:Movie {title:{title}})")
    .WithParam("title", title)
    .Return(() => Return.As<Node<Dictionary<string,string>>>("movie"));

var results = resQuery.Results.Select(r => r.Data);
Console.WriteLine(results.First()["title"]);

Alternatively, something like:

var resQuery = WebApiConfig.GraphClient.Cypher
    .Match("(movie:Movie {title:{title}})")
    .WithParam("title", title)
    .Return(() => Return.As<Node<string>>("movie"));

var results = resQuery.Results;
List<dynamic> nodes = results.Select(r => JsonConvert.DeserializeObject<dynamic>(r.Data)).ToList();
Console.WriteLine(nodes[0].title);


来源:https://stackoverflow.com/questions/36006264/build-a-dynamic-query-using-neo4j-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!