neo4j/neo4j-dotnet-driver

Name: neo4j-dotnet-driver

Owner: Neo4j

Description: Neo4j Bolt driver for .NET

Created: 2016-01-11 12:28:56.0

Updated: 2018-05-22 10:02:10.0

Pushed: 2018-05-24 12:49:58.0

Homepage:

Size: 6706

Language: C#

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Neo4j .NET Driver

This is the official Neo4j .NET driver for connecting to Neo4j 3.0.0+ databases via in-house binary protocol Bolt.

Resources to get you started:

For Application Developers

This section is prepared for application developers who would like to use this driver in appliation projects for connecting to a Neo4j instance or a Neo4j cluster.

Getting the Driver

The Neo4j Driver is distributed exclusively via Nuget.

Add the driver to your project using the Nuget Package Manager:

Install-Package Neo4j.Driver

There is also a strong named version of the driver available on Nuget as Neo4j.Driver.Signed. Both packages contain the same version of the driver, only the latter is strong named. Consider using the strong named version only if your project is strong named and/or you are forced to use strong named dependencies.

Add the strong named version of the driver to your project using the Nuget Package Manager:

Install-Package Neo4j.Driver.Signed
Minimum Viable Snippet

Connect to a Neo4j database

ver driver = GraphDatabase.Driver("bolt://localhost:7687", AuthTokens.Basic("username", "pasSW0rd"));
g(ISession session = driver.Session())

IStatementResult result = session.Run("CREATE (n) RETURN n");

er.Dispose();

There are a few points that need to be highlighted when adding this driver into your project:

Parsing Result Values
Record Stream

A cypher execution result is comprised of a stream records followed by a result summary. The records inside the result are accessible via IEnumerable interface on IStatementResult. Our recommended way to access these result records is to make use of Linq methods such as Single, ToList, Select.

Process result records using Linq:

tementResult result = tx.Run("MATCH (a:Person) RETURN a.name as name");
<string> people = result.Select(record => record["name"].As<string>()).ToList();

The records are exposed as a record stream in the sense that:

For example, given a record stream in a result:

| Keys | “name” | | ——-: | :—– | | Record 0 | “Bruce Wayne” | | Record 1 | “Selina Kyle” |

Visiting the record stream when consumed as IEnumerable (i.e. if not converted to List or Array):

lt.First(); // Bruce Wayne
lt.First(); // Selina Kyle as you already consumed the previous "first" record!
Value Types

The driver currently exposes values in the record in the record as of object type. The underlying types of the returned values depend on the corresponding Cypher types.

The mapping between Cypher types and the types used by this driver (to represent the Cypher type):

| Cypher Type | Driver Type | —: | :— | | null | null | | List | IList< object > | | Map | IDictionary | | Boolean| boolean | | Integer| long | | Float| float | | String| string | | ByteArray| byte[] | | Point| Point | | Node| INode | | Relationship| IRelationship | | Path| IPath |

To convert from object to the driver type, a helper method ValueExtensions#As<T> is available:

ord record = result.First();
ng name = record["name"].As<string>();
Temporal Types - Date and Time

The new temporal types in Neo4j 3.4 series are introduced with the 1.6 series of the driver. Considering the nanosecond precision and large range of supported values, all temporal types are backed by custom types at the driver level.

The mapping among the Cypher temporal types, driver types, and convertible CLR temporal types - DateTime, TimeSpan and DateTimeOffset - (via IConvertible interface) are as follows:

| Cypher Type | Driver Type | Convertible CLR Type | | :———-: | :———–: | :——-: | | Date | LocalDate | DateTime | | Time | OffsetTime | — | | LocalTime| LocalTime | TimeSpan, DateTime | | DateTime | ZonedDateTime | DateTimeOffset | | LocalDateTime | LocalDateTime | DateTime | | Duration | Duration | — |

Receiving a temporal value as driver type:

ord record = result.Single();
dDateTime datetime = record["datetime"].As<ZonedDateTime>();

Converting a temporal value to the CLR type:

ct record = result.Single()["datetime"];

TimeOffset datetime = record["datetime"].As<DateTimeOffset>();
hich is equivalent to
onedDateTime cyDatetime = record["datetime"].As<ZonedDateTime>();
ateTimeOffset datetime = cyDatetime.ToDateTimeOffset();

Note:

For Driver Developers

This section targets at people who would like to compile the source code on their own machines for the purpose of, for example, contributing a PR to this repository. Before contributing to this project, please take a few minutes and read our Contributing Criteria.

Snapshots

Snapshot builds are available at our MyGet feed, add the feed to your Nuget Sources to access snapshot artifacts.

Building the Source Code
Visual Studio Version

The driver is written in C# 7 so will require Visual Studio 2017.

Integration Tests

The integration tests use boltkit to download and install a database instance on your local machine. They can fail for three main reasons:

  1. Python.exe and Python scripts folder is not installed and added in the system PATH variable
  2. The tests aren't run as Administrator (you'll need to run Visual Studio as administrator)
  3. You have an instance of Neo4j already installed / running on your local machine.

The database installation uses boltkit neoctrl-install command to install the database. It is possible to run the integration tests against a specific version by setting environment variable NeoctrlArgs.

Run tests

The simplest way to run all tests from command line is to run runTests.ps1 powershell script:

.\Neo4j.Driver\runTests.ps1

Any parameter to this powershell script will be used to reset environment variable NeoctrlArgs:

.\Neo4j.Driver\runTests.ps1 -e 3.3.0

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.