.NET driver

This section presents the breaking changes between the Neo4j 1.7 .NET driver and 4.x .NET driver.

The latest version of the .NET driver for Neo4j can be found on the .NET driver’s official page.

  • The Neo4j.Driver package contains only the asynchronous API.

  • The IDriverLogger has been renamed to ILogger.

  • TrustStrategy is replaced with TrustManager.

Example 1. Example of changes between the 1.7 and 4.0 .NET drivers
Example code for the 4.0 .NET driver Example code for the 1.7 .NET driver
using Neo4j.Driver.Simple;
...
private readonly IDriver _driver;
private readonly string _previousNeo4jSessionBookmark;
...
public void PrintGreeting(string message)
{
   using (ISession session = _driver.Session(o =>
      o.WithDatabase("neo4j")
       .WithDefaultAccessMode(AccessMode.Write)
       .WithBookmarks(_previousNeo4jSessionBookmark)))
   {
       using (ITransaction transaction = session.BeginTransaction())
       {
           Query query = new Query("CREATE (a:Greeting) SET a.message = $message RETURN a.message + ', from node ' + id(a)", new Dictionary<string, object>{{"message", message}});
           IResult result = transaction.Run(query);

                string greeting = result.Single()[0].As<string>();
                Console.WriteLine(greeting);
                transaction.Commit(); // commit immediately here
            }
        _previousNeo4jSessionBookmark = session.LastBookmark;
        }
     }
using Neo4j.Driver;
...
private readonly IDriver _driver;
private readonly string _previousSessionBookmark;
...
public void PrintGreeting(string message)
{
   using (ISession session =_driver.Session(
      AccessMode.Write, _previousSessionBookmark))
   {


      using (ITransaction transaction = session.BeginTransaction())
      {
         Statement query = new Statement("CREATE (a:Greeting) SET a.message = $message RETURN a.message + ', from node ' + id(a)", new Dictionary<string, object>{{"message", message}});
          IStatementResult result = transaction.Run(query);
          transaction.Success(); // mark success, actually commit will happen in transaction.Dispose()
          var greeting = result.Single()[0].As<string>();
          Console.WriteLine(greeting);
   }
   _previousSessionBookmark = session.LastBookmark;
   }
}