Issue with .NET Hello World

I'm 100% new to Neo4j, and a bit of a neophyte in coding as well. I have a project that I want to test the usefulness of a graph database for and have downloaded the Neo4j Community edition. I have been running through some of the tutorials, and I came into an issue with the HelloWorld code used in the .NET example. Particularly this line

return result.Single()[0].As();

Visual Studio 2017 does not understand what type it is supposed to be cast to. After almost an hour of researching (Again I am new to programming), I finally found that the following change worked.

return result.Single()[0].As<string>();

or even

return result.Single()[0]; 

What was the code supposed to be doing? Or is it supposed to be casting to a specific type?

Thank you,
Mike Fontaine

@chris.skardon can you help here? Thx

Wow, totally missed this - yes, it should have been return result.Single()[0].As<string>();

The As<> bit is the type you're pulling from the database, so, in the example, because you're doing:

"RETURN a.message + ', from node ' + id(a)",

You are returning a string.

If you did:

"RETURN id(a)" instead, you would do:

return result.Single()[0].As<int>()

though if you did <string> that would work as well, as .NET can cast the int into a string as well as an int.

Does that make sense?

1 Like