简体   繁体   English

从C#中的Neo4j数据库返回所有节点

[英]Return all nodes from Neo4j database in c#

I am still very new to programming, but what I am trying to reach for now is a piece of code that will show me all of my nodes in my Visual studio. 我对编程还是很陌生,但是我现在想要实现的是一段代码,它将向我展示Visual Studio中的所有节点。 I connected my c# to my database, but what I can't see why I can't show back my nodes. 我将c#连接到数据库,但是看不到为什么无法回显节点。 The .Results is giving an error and I can't see why. .Results提供了一个错误,我看不出为什么。 My code is looking like this so far. 到目前为止,我的代码看起来像这样。 Could someone explain what and more importantly why this piece is not working? 有人可以解释什么,更重要的是为什么这部分不起作用?

class DatabaseConnection
{
    GraphClient dbclient;

    public DatabaseConnection(){
        dbclient = new GraphClient(new Uri("http://localhost:7474/db/data"));
        dbclient.Connect();

        dbclient.Cypher
        .Match("(type:PhonePart)")
        .Return(type => type.As<PhoneItems>())
        .Results
    }

}
public class PhoneItems
{
    public string PhonePart { get; set; }  
}

Your issue here is actually with C# syntax, not Neo4j at all. 您的问题实际上是C#语法,而不是Neo4j。

This error is because you've referenced a property, Results , but not told the compiler what to do with it. 此错误是因为您已引用了Results属性,但没有告诉编译器该怎么做。 It's like typing 3 in your code and then just leaving it hanging: do you want it assigned to a variable, printed out, or something else? 就像在代码中键入3 ,然后将其挂起一样:是否要将其分配给变量,打印出来还是其他?

All you need to do is assign this to something: 您需要做的就是将它分配给某些东西:

dbclient.Cypher
    .Match("(type:PhonePart)")
    .Return(type => type.As<PhoneItems>())
    .Results

Like so: 像这样:

var phoneItems = dbclient.Cypher
    .Match("(type:PhonePart)")
    .Return(type => type.As<PhoneItems>())
    .Results;

Then, your code will compile. 然后,您的代码将被编译。

Next, you want to do something with these phone numbers, maybe like so: 接下来,您想对这些电话号码进行处理,也许是这样的:

foreach (var phone in phoneItems)
{
    Console.WriteLine(phone.PhonePart);
}

Hope that helps! 希望有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM