Polypheny .NET Driver

Use the Polypheny .NET driver for SQL, MongoQL (MQL), Cypher and entity metadata over the Prism query interface. The driver uses ADO.NET types for connections, commands, transactions, and SQL data readers. See the C# integration guide for complete examples.

Versions and installation

The released driver is PolyphenyDotNetDriver 2.1.0. It targets .NET 6 and can be used from later compatible .NET versions. Use the .NET 8 SDK for the examples and tests. NuGet also restores the Polypheny.Prism 2.3.0 bindings.

Add the driver to your application project.

dotnet add package PolyphenyDotNetDriver --version 2.1.0

Import the PolyphenyDotNetDriver namespace. Entity metadata uses types from the transitive Polypheny.Prism package. Connect to a compatible Prism 2.x server. Document collection metadata requires server support introduced in Prism 2.2, and Cypher requires Prism 2.3 graph support. Client and server minor versions do not have to match exactly.

Build from source

To build the same release from source, check out its tag and build the driver project. Applications can use the NuGet package above without a source checkout.

git clone --branch v2.1.0 --depth 1 https://github.com/polypheny/Polypheny-DotNet-Driver.git
dotnet build Polypheny-DotNet-Driver/PolyphenyDotNetDriver/PolyphenyDotNetDriver.csproj -p:Version=2.1.0

Connections and transactions

API Behavior
PolyphenyDriver.OpenConnection(connectionString) Constructs a PolyphenyConnection with the default configuration. Call Open() or OpenAsync() to connect.
new PolyphenyConnection(connectionString, config) Constructs a connection with explicit PolyphenyConfig. The Database and DataSource values are labels. The transport version defaults to plain-v1@polypheny.com\n.
Open() and OpenAsync(cancellationToken) Connect and negotiate the transport and Prism protocol.
State and Ping() Report the local connection state and send a connection check, respectively.
CreateCommand() Creates an ADO.NET command associated with the connection. For a typed PolyphenyCommand, use the fluent constructor shown in the integration guide.
BeginTransaction() Creates a transaction handle. The Prism session defaults to manual commits.
Commit() and CommitAsync(cancellationToken) Commit pending writes on the connection.
Rollback() and RollbackAsync(cancellationToken) Discard pending writes on the connection.
Close(), CloseAsync(), and Dispose() Close the connection. Close() and CloseAsync() send a Prism disconnect request when the connection is open.

The connection string is host:port,user:password. The parser uses commas and colons as delimiters and supports DNS names and IPv4 addresses. For a local Prism interface with its default port and credentials, use localhost:20590,pa:. To select a namespace, qualify SQL entity names, or pass the namespace explicitly for MQL and metadata. Complete one operation before starting another on the same connection.

Commands and results

API Behavior
WithConnection(connection), WithCommandText(text) Associate a newly constructed command with a connection and set its statement text.
WithTransaction(transaction) Associate a command with a transaction from the same connection.
WithParameterValues(values), Prepare(), PrepareAsync(cancellationToken) Supply values for positional SQL ? placeholders and prepare the command for ExecuteNonQuery(). Bind values in placeholder order.
ExecuteNonQuery() and ExecuteNonQueryAsync(cancellationToken) Run SQL that returns a scalar update count, including data and schema writes.
ExecuteReader() and ExecuteReaderAsync() Run unparameterized SQL and read relational rows. The synchronous method returns a PolyphenyDataReader, and the asynchronous ADO.NET method returns a DbDataReader.
ExecuteQueryMongo(namespaceName) Run a MongoQL query that returns a document result. The parameterless overload uses the server’s default namespace.

Use Read() or ReadAsync() to move through SQL rows. Access columns by zero-based ordinal or by name, and use IsDBNull() before reading a nullable column with a typed getter. FieldCount, GetName(), and GetOrdinal() expose the available columns. SQL readers and document queries materialize the first result frame. Cypher results provide the paging methods described below.

Positional SQL parameters accept int, long, float, double, string, and bool. The same value types can be read from SQL and MQL results. Document keys are strings in a Dictionary<object, object>, lists are object[], and Prism null values are C# null.

ExecuteScalar(), Cancel(), and ChangeDatabase() throw NotImplementedException. Isolation levels and command timeouts are currently not applied to the Prism request. Support for asynchronous execution and cancellation varies by method.

Cypher

PolyphenyCommand.ExecuteCypher(namespaceName, fetchSize) and ExecuteCypherAsync(namespaceName, fetchSize) execute one Cypher statement in the named graph namespace. Use a positive fetch size. The default is 100 source rows. A source row can yield several graph elements. Use a graph namespace on a server with Cypher enabled.

Kind Properties for the current page
CypherResultKind.Graph Elements contains a flat sequence of GraphNode and GraphEdge values in projection and traversal order.
CypherResultKind.Rows Columns contains Prism column metadata. Rows contains values in column order, including typed graph values in mixed projections.
CypherResultKind.Scalar RowsAffected contains the update count or acknowledgement for a write.

PolyphenyCypherResult exposes the first page immediately after execution. Use FetchNext() or FetchNextAsync() to advance until it returns false. An empty page can occur before the last page. IsLast identifies the final page. IsClosed tracks whether the result has been closed. Each fetch replaces the current page. Keep your own references to values you need from previous pages. Close the result with using or await using before reusing the connection, even if you do not read every page. Await each operation on a connection before starting the next one. A result belongs to the session that created it. Reopening the connection starts a new session, and an incomplete result from the earlier session raises an error on fetch.

Value Members
GraphNode Id, Name, Labels, Properties
GraphEdge Id, Name, Labels, Properties, plus Left, Right and Direction (LeftToRight, RightToLeft, None or Unspecified). Endpoint IDs and direction describe the edge itself, even in a reverse traversal.
GraphPath Nodes and Edges in traversal order
GraphValue Nodes and Edges of a whole graph, including isolated nodes. Order is unspecified.

Inspect property values as .NET objects. Name identifies the name supplied by Prism. To read a graph property named name, use Properties["name"]. Lists and documents can contain nested graph values, and Prism nulls appear as C# null. Exact decimals use PolyphenyDecimal and retain the unscaled integer and scale. Binary and file values are byte[]. Dates and timestamps are UTC DateTime values, and times of day use TimeSpan. Intervals use PolyphenyInterval with signed Months and Milliseconds components. Use the direct Cypher execution methods for one statement at a time. Set PolyphenyConfig.AutoCommit when constructing a connection to enable auto-commit. Finish or dispose the active result before executing another statement in that mode. For manual transactions, use the connection’s commit and rollback API. See the complete Cypher example.

Entity metadata

Call SearchEntities(namespaceName, entityPattern) or SearchEntitiesAsync(namespaceName, entityPattern) on an open connection. Both return an IReadOnlyList<Polypheny.Prism.Entity>. Omit the optional second argument to list the namespace. The server applies the pattern if you supply it.

Relational entries expose Entity.Table and graph entries use the Entity.Graph marker. Document collection entries expose Entity.Document with the following properties.

Property Meaning
NamespaceName, CollectionName Identify the collection.
Fields Each DocumentField has a FieldPath, TypeName, and IsOptional. Paths can identify nested keys using dots, and optional fields may be absent or null. Field information can be inferred from sampled documents.
HasSampleDocumentJson, SampleDocumentJson Indicate whether a sample was returned and hold its JSON text. Check presence before reading the sample.
DocumentIndexes Each DocumentIndex reports FieldPath, IndexType, and Unique. The collection and storage adapter determine which indexes are available.

See the Prism document metadata reference for the underlying messages.

© Polypheny GmbH. All Rights Reserved.