0

我创建了一个方法,它接受节点属性并更新指定节点上的这些属性,但是当它到达代码进行更新时,我得到一个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;
        }
4

1 回答 1

1

看起来clientConnection您正在实例化的是另一个名为的类GraphOperations
虽然您可能在此类中有一个同名的变量,但该类不会分配它GraphOperations。将您的代码更新为以下内容:

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

这将创建一个范围变量,但是如果要将其分配给此类中的“变量”,请执行以下操作var

clientConnection = graphOp.GraphGetConnection();
于 2013-05-17T09:06:51.867 回答