PolyphenyDotNetDriver 2.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package PolyphenyDotNetDriver --version 2.1.0
                    
NuGet\Install-Package PolyphenyDotNetDriver -Version 2.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PolyphenyDotNetDriver" Version="2.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PolyphenyDotNetDriver" Version="2.1.0" />
                    
Directory.Packages.props
<PackageReference Include="PolyphenyDotNetDriver" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add PolyphenyDotNetDriver --version 2.1.0
                    
#r "nuget: PolyphenyDotNetDriver, 2.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package PolyphenyDotNetDriver@2.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=PolyphenyDotNetDriver&version=2.1.0
                    
Install as a Cake Addin
#tool nuget:?package=PolyphenyDotNetDriver&version=2.1.0
                    
Install as a Cake Tool

<p align="center"> <a href="https://polypheny.org/"> <picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/polypheny/Admin/master/Logo/logo-white-text_cropped.png"> <img width='50%' alt="Light: 'Resume application project app icon' Dark: 'Resume application project app icon'" src="https://raw.githubusercontent.com/polypheny/Admin/master/Logo/logo-transparent_cropped.png"> </picture> </a> </p>

Polypheny .NET Driver

Connect .NET applications to Polypheny-DB over the Prism query interface. The driver supports SQL, MongoQL (MQL) and Cypher.

Requirements

  • The driver targets .NET 6. Use the .NET 8 SDK to run this repository's tests.
  • Connect to a Polypheny-DB server with a compatible Prism 2.x interface. Document collection metadata needs server support introduced in Prism 2.2. A Prism 1.x server requires an earlier driver.
  • Cypher queries require a server with Cypher enabled over Prism 2.3. The driver uses the published Polypheny.Prism 2.3.0 NuGet package.
  • Enable the Prism query interface on the server. The examples use its default TCP port 20590 and the local development credentials pa with an empty password.

See the Polypheny-DB setup instructions to start a server.

Installation

Clone the repository and reference the driver project from your .NET application:

git clone https://github.com/polypheny/Polypheny-DotNet-Driver.git
dotnet add MyApp.csproj reference ./Polypheny-DotNet-Driver/PolyphenyDotNetDriver/PolyphenyDotNetDriver.csproj

Run the second command from the directory containing MyApp.csproj and the checkout. To build a local NuGet package, run the following from the repository root:

dotnet pack PolyphenyDotNetDriver/PolyphenyDotNetDriver.csproj -c Release

Run SQL

using PolyphenyDotNetDriver;

using var connection = PolyphenyDriver.OpenConnection("localhost:20590,pa:");
connection.Open();

using var command = new PolyphenyCommand()
    .WithConnection(connection)
    .WithCommandText("SELECT * FROM emps");
using var reader = command.ExecuteReader();
while (reader.Read())
{
    Console.WriteLine(reader["name"]);
}

Use ExecuteNonQuery() for DDL and DML. Use parameters for SQL data values. This example assumes an existing customers table with id and name columns.

using var transaction = connection.BeginTransaction();
using var insert = new PolyphenyCommand()
    .WithConnection(connection)
    .WithTransaction(transaction)
    .WithCommandText("INSERT INTO customers (id, name) VALUES (?, ?)")
    .WithParameterValues(new object[] { 1, "Alice" });
insert.Prepare();
insert.ExecuteNonQuery();
transaction.Commit();

Call transaction.Rollback() to discard uncommitted DML.

Query documents

Supply the namespace when executing a query against a document collection. In this example, patients contains a collection named symptoms.

using var query = new PolyphenyCommand()
    .WithConnection(connection)
    .WithCommandText("db.symptoms.find()");

foreach (var document in query.ExecuteQueryMongo("patients"))
{
    Console.WriteLine(document["patient_id"]);
}

Document keys are strings. Nested documents are dictionaries and lists are object arrays.

Query graphs with Cypher

Set the graph namespace explicitly. A graph-only projection returns a flat page of nodes and edges in Elements. This example assumes a graph namespace named social containing Person nodes.

using var query = new PolyphenyCommand()
    .WithConnection(connection)
    .WithCommandText("MATCH (n:Person) RETURN n");
using var result = query.ExecuteCypher("social", fetchSize: 100);
do
{
    foreach (var node in result.Elements.OfType<GraphNode>())
        Console.WriteLine($"{node.Id}: {node.Properties["name"]}");
} while (result.FetchNext());

Use ExecuteCypherAsync, FetchNextAsync and await using for asynchronous access. An empty non-final page can occur, so continue fetching until FetchNext returns false. Fetch size counts source rows. A row containing a node, an edge and another node can therefore produce three elements.

Mixed graph and scalar projections return columns and rows. The example keeps the column order from RETURN.

using var mixed = new PolyphenyCommand()
    .WithConnection(connection)
    .WithCommandText("MATCH (n:Person) RETURN n AS node,n.name AS name")
    .ExecuteCypher("social", fetchSize: 100);
do
{
    foreach (var row in mixed.Rows)
    {
        var node = (GraphNode)row[0];
        Console.WriteLine($"{node.Id}: {row[1]}");
    }
} while (mixed.FetchNext());

GraphNode and GraphEdge retain identifiers, names, labels and recursively decoded properties. Edges also expose Left, Right and Direction. A path in a mixed projection is a GraphPath, whose Nodes and Edges follow traversal order. An edge retains its original endpoints and direction when traversed in reverse. A whole-graph value in a row is a GraphValue, including isolated nodes. Standalone paths and whole-graph queries use the flat graph stream, where path boundaries are not available. Exact decimal values, including Cypher numeric literals, are represented by PolyphenyDecimal. Its UnscaledValue and Scale preserve the value as UnscaledValue * 10^(-Scale). ToString() uses an exact base-10 exponent representation. Binary and file values decode to byte arrays. Dates and timestamps are UTC DateTime values, times are TimeSpan values, and PolyphenyInterval preserves the separate Months and Milliseconds components of an interval.

Inspect Kind to distinguish Graph, Rows and Scalar results. RowsAffected is populated for scalar command acknowledgments. Cypher statements producing relational results, including update-count rows, expose those values through Rows. Dispose every result to close its server statement, including partially fetched results. The connection can then execute another query. Run one operation at a time on a connection. Fetching and disposing the same result are serialized so disposal waits for its pending page response. Results belong to the session that created them. Reopening a connection does not reactivate old results.

Connections use manual transactions by default. Use connection.BeginTransaction().Commit() or Rollback() for graph writes. For autocommit, construct a connection with new PolyphenyConfig { AutoCommit = true }. Prism accepts one Cypher statement per request. Prepared and parameterized Cypher statements are unsupported.

Discover entity metadata

Use SearchEntities or SearchEntitiesAsync on an open connection. Supply a server-side name pattern to filter results, or omit it to list the namespace.

foreach (var entity in connection.SearchEntities("patients", "symptoms"))
{
    if (entity.Document is not { } collection)
        continue;

    Console.WriteLine($"{collection.NamespaceName}.{collection.CollectionName}");
    foreach (var field in collection.Fields)
        Console.WriteLine($"{field.FieldPath}: {field.TypeName}, optional: {field.IsOptional}");

    if (collection.HasSampleDocumentJson)
        Console.WriteLine(collection.SampleDocumentJson);

    foreach (var index in collection.DocumentIndexes)
        Console.WriteLine($"{index.FieldPath}: {index.IndexType}, unique: {index.Unique}");
}

Fields may be inferred from a bounded sample. An empty collection can have no sample JSON. Index metadata depends on what the server and storage adapter expose. Searching a relational namespace returns table metadata in Entity.Table.

Run the tests

Run the unit and loopback protocol tests without a database:

dotnet test PolyphenyDotNetDriver.Tests/PolyphenyDotNetDriver.Tests.csproj --filter 'TestCategory!=Integration'

Use a dedicated Polypheny test server for the integration tests, which create and drop tables. The default endpoint is localhost:20590,pa:. Set POLYPHENY_TEST_CONNECTION to use another endpoint. The graph integration tests also create a private graph namespace, exercise paging and transaction handling, and remove that namespace. They require the Prism 2.3 graph server described above.

dotnet test PolyphenyDotNetDriver.Tests/PolyphenyDotNetDriver.Tests.csproj --filter 'TestCategory=Integration'

For an interactive coverage report, install dotnet-reportgenerator-globaltool and run test.sh from PolyphenyDotNetDriver.Tests with the test server running.

Release the driver

Run the .NET driver release workflow with a stable tag such as v2.0.0 to test and download the NuGet package from GitHub Actions. Publishing a stable GitHub release with that tag attaches the package to the release and pushes the same package to NuGet.org.

Roadmap

See the open issues for a list of proposed features (and known issues).

Contributing

We highly welcome your contributions to the Polypheny .NET Driver. If you would like to contribute, please fork the repository and submit your changes as a pull request. Please consult our Admin Repository and our Website for guidelines and additional information.

Please note that we have a code of conduct. Please follow it in all your interactions with the project.

License

The Apache 2.0 License

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.2.0 97 11/23/2026
2.1.0 105 11/21/2026
2.0.0 110 11/15/2026