我有两个表:
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/cypher或https://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/cypher和https://github.com/Readify/Neo4jClient/wiki/cypher-examples。
关于c# - 将密码查询转换为C#,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20631048/