更新节点Neo4jClient .NET时出现空引用异常

时间:2013-05-17 08:36:48

标签: c# .net neo4jclient

我创建了一个方法,它接受节点属性并更新指定节点上的那些属性,但当它到达代码进行更新时,我得到System.NullReferenceException: Object reference not set to an instance of an object.

以下是代码:

public NodeReference<EntityNode> GraphUpdateEntityNode(
                        NodeReference<EntityNode> nodeId,
                        string guid,
                        string type,
                        string name,
                        string dateTimeCreated,
                        string currentVersionDateTimeCreated,
                        int versionCount,
                        int currentVersion)
{
    var nodeRef = (NodeReference<EntityNode>)nodeId;

    GraphOperations graphOp = new GraphOperations();
    graphOp.GraphGetConnection();

    clientConnection.Update(nodeRef, node =>
    {
        node.GUID = guid;
        node.Type = type;
        node.Name = name;
        node.CurrentVersion = currentVersion;
        node.DateTimeCreated = dateTimeCreated;
        node.CurrentVersionDateTimeCreated = currentVersionDateTimeCreated;
        node.VersionCount = versionCount;
    });

    return nodeRef.Id;
}

我在这里缺少什么?我是否必须通过执行var nodeRef = (NodeReference<EntityNode>)nodeId;再次获取节点的引用,因为我已经将其作为方法的参数传入?在更新节点之前,我是否必须调用抽象的clientConnection.Connect

这是GraphGetConnection()方法:

GraphClient clientConnection;
public GraphClient GraphGetConnection()
        {
            GraphOperationsLogger.Trace("Entering GetConnection Method");

                clientConnection = new GraphClient(new Uri("http://localhost:7474/db/data"));
                clientConnection.Connect();

            return clientConnection;
        }

1 个答案:

答案 0 :(得分:1)

看起来你正在实例化的clientConnection在另一个名为GraphOperations的类中。虽然你可能在这个类中有一个同名的变量,但{} { {1}}课程。 将您的代码更新为以下内容:

GraphOperations

这将创建一个范围变量,但是如果要将其分配给此类中的“变量”,请执行以下操作而不使用GraphOperations graphOp = new GraphOperations(); var clientConnection = graphOp.GraphGetConnection();

var