Reputation: 21
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. I connected my c# to my database, but what I can't see why I can't show back my nodes. The .Results is giving an error and I can't see why. 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; }
}
Upvotes: 2
Views: 748
Reputation: 4290
Your issue here is actually with C# syntax, not Neo4j at all.
This error is because you've referenced a property, Results
, but not told the compiler what to do with it. 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?
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!
Upvotes: 4