将密码查询转换为C#

塞夫卡夫鲁

我有两个表:

 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);

如何创建正确的集合以保存数据?

塔瑟姆·奥迪

听起来您还没有阅读https://github.com/Readify/Neo4jClient/wiki/cypherhttps://github.com/Readify/Neo4jClient/wiki/cypher-examples您真的应该从这里开始。它有助于阅读手册。我不只是为了好玩而写。

对于您的特定情况,让我们从Cypher查询开始:

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

现在,我们将其转换为流畅的Cypher:

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

然后,您可以轻松地使用它:

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

您将需要与您的节点属性模型匹配的此类,如下所示:

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; }
}

同样,继续阅读https://github.com/Readify/Neo4jClient/wiki/cypherhttps://github.com/Readify/Neo4jClient/wiki/cypher-examples

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章