简体   繁体   中英

Null Reference Exception when Updating a Node Neo4jClient .NET

I have created a method that takes in node properties and updates those proerties on a specified Node, but when it get to the code to do the update I get a System.NullReferenceException: Object reference not set to an instance of an object.

Here is the code:

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;
}

What am I missing here? Do I have to get the reference for the node again by doing var nodeRef = (NodeReference<EntityNode>)nodeId; because Im already passing it in as a parameter for the method? And do I have to call my abstracted clientConnection.Connect before I update the node?

Here is the GraphGetConnection() method:

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

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

            return clientConnection;
        }

It looks like the clientConnection you are instantiating is in another class called GraphOperations
While you might have a variable with the same name in this class it will not be assigned by the GraphOperations class. Update your code to the following:

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

Which will create a scope variable, but if you want to assign it to the 'variable' in this class do the following without var :

clientConnection = graphOp.GraphGetConnection();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM