2013-12-17 51 views
2

我有两个表:转换暗号查询到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); 

如何建立正确的收集保存数据?

回答

3

这听起来像你有没有看过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) 

现在,我们将其转换成流利的暗号:

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

+0

谢谢)完美的作品。 –

-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(); 
+0

首先我需要ExecuteGetCypherResults 。 –