Convert cypher query to c#

…衆ロ難τιáo~ 提交于 2020-01-04 09:05:33

问题


I have two tables:

 User
   Name
   Surname

 Phone
   number
   type_of_number



var myList = ((IRawGraphClient) client).ExecuteGetCypherResults<**i_need_class_to_save_it**>(
                    new CypherQuery("match (a:User)-[r]->(b:Phone) return a,collect(b)", null, CypherResultMode.Set))
                .Select(un => un.Data);

How create correct collection to save data?


回答1:


It sounds like you haven't read https://github.com/Readify/Neo4jClient/wiki/cypher or https://github.com/Readify/Neo4jClient/wiki/cypher-examples. You really should start there. It helps to read the manual. I don't just write it for fun.

For your specific scenario, let's start with your Cypher query:

MATCH (a:User)-[r]->(b:Phone)
RETURN a, collect(b)

Now, we convert that to fluent Cypher:

var results = client.Cypher
    .Match("(a:User)-[r]->(b:Phone)")
    .Return((a, b) => new {
        User = a.As<User>(),
        Phones = b.CollectAs<Phone>()
    })
    .Results;

You can then use this rather easily:

foreach (var result in results)
    Console.WriteLine("{0} has {1} phone numbers", result.User.Name, result.Phones.Count());

You will need classes like these, that match your node property model:

public class User
{
    public string Name { get; set; }
    public string Surname { get; set; }
}

public class Phone
{
    public string number { get; set; }
    public string type_of_number { get; set; }
}

Again, please go and read https://github.com/Readify/Neo4jClient/wiki/cypher and https://github.com/Readify/Neo4jClient/wiki/cypher-examples.




回答2:


Add a .ToList() at the end of your command? Like this :

var myList = ((IRawGraphClient) client).ExecuteGetCypherResults<**i_need_Collection**>(
                    new CypherQuery("match (a:User)-[r]->(b:Phone) return a,collect(b)", null, CypherResultMode.Set))
                .Select(un => un.Data).ToList();


来源:https://stackoverflow.com/questions/20631048/convert-cypher-query-to-c-sharp

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