我有两张桌子:
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);
如何创建正确的集合来保存数据?
答案 0 :(得分:3)
听起来你还没有看过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。
答案 1 :(得分:-1)
在命令末尾添加.ToList()? 像这样:
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();