This is a two part question
I am getting this error when i try to create a new node
Cannot implicitly convert type'Neo4jClient.NodeReference' to 'Neo4jClient.GraphClient'
I have 3 classes here The first connects to the GraphDB server and return the client variable for later use in other classes
public GraphClient GetConnection()
{
var client = new GraphClient(new Uri("http://localhost:7474/db/data"));
client.Connect();
return client;
}
Then there is the New_Node class that looks like this
class New_Node
{
public GraphClient Node { get; set; }
}
Then there is the Graph Operations class that has the CreateNode Method
public GraphClient CreateNode()
{
Graph_Connection connection = new Graph_Connection();
var NewNode = connection.GetConnection();
var Created_Node = NewNode.Create(new New_Node());
return Created_Node;
}
how do I set the property of the Node on another line of code instead of creating them with the node, I want to make my app more dynamic, where as this way seems very hard coded
var refA = client.Create(new Person() { Name = "Person A" });
In Java one can do this
Node user1 = this.graphDb.createNode();
user1.setProperty("name", "Mike");
The problem is that you're trying to persist the DB connection inside the node itself.
Here's your definition of the node's data structure:
class New_Node
{
public GraphClient Node { get; set; }
}
That says that you want a property on the node called "Node" that holds the connection to the DB that contains the node. Tongue twisted yet? Mine is.
Based on your Java comparison, I think you want your node to actually look like this:
class New_Node
{
public string Name { get; set; }
}
That says you want a node with a Name property, which is a string.
Then, you can create it like so:
graphClient.Create(new New_Node { Name = "Mike" });
In relation to your sub question, "1.how do I set the property of the Node on another line of code instead of creating them with the node", when you call graphClient.Create
we are persisting it to the DB. Any later property changes are updates to the DB, and more calls.
Just call create when your node is ready to be persisted.
var node = new New_Node();
... think ...
node.Name = "Mike";
... think ...
graphClient.Create(node);
Basically, every time you call graphClient.Something
we hit the DB. This is because we're going over a stateless API. This is different to the Java driver which is talking to the DB in memory (assuming you're talking about an embedded Neo4j instance).
HTH.
-- Tatham