下面您将看到我的 GraphOperations 类(用C#
using编写Neo4jClient
),它执行基本的Neo4j
图形操作。该GraphGetConnection()
方法连接到 Neo4j 并返回clientConnection
,我的CreateNode()
方法创建了一个节点并返回其节点引用。
现在在那个方法中,你会看到我要去GraphOperations graphOp = new GraphOperations();
然后clientConnection= graphOp.GraphConnection();
。
- 这是正确的方法吗?
- 每次我想执行操作时都调用连接吗?
- 如何优化下面的代码?我想为每个 CRUD 操作创建一个方法,并希望找到执行此操作的最佳方法。
我希望这个问题足够清楚?
using Neo4jClient;
public class GraphOperations
{
GraphClient clientConnection;
public GraphClient GraphGetConnection()
{
clientConnection = new GraphClient(new Uri("http://localhost:7474/db/data"));
clientConnection.Connect();
return clientConnection;
}
public long GraphCreateNode(string type, string name, string customerName, string documentReference, int newVersionNumber)
{
Guid nodeGuid = Guid.NewGuid();
System.DateTime dateTime = System.DateTime.Now;
string timeStamp = String.Format("{0:dd MMMM yyyy HH:mm:ss}", dateTime);
GraphOperations graphOp = new GraphOperations();
clientConnection = graphOp.GraphGetConnection();
var createNode = clientConnection.Create(new VersionNode()
{
GUID = nodeGuid.ToString(),
Name = name,
Type = type,
DocumentReference = documentReference,
DateTimeCreated = timeStamp,
Version = newVersionNumber
});
return createNode.Id;
}
}