neo4j-driver-dotnet-skill

Implement Neo4j .NET Driver v6 IDriver lifecycle and managed transactions in C#.

101|35|Updated Jan 20, 2026
One-click install
npx skills add https://github.com/neo4j-contrib/neo4j-skills --skill neo4j-driver-dotnet-skill
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: neo4j-driver-dotnet-skill
Source: https://github.com/neo4j-contrib/neo4j-skills/tree/main/neo4j-driver-dotnet-skill
Command: npx skills add https://github.com/neo4j-contrib/neo4j-skills --skill neo4j-driver-dotnet-skill

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

It solves the problem of writing correct, production-ready Neo4j connection and query code in C#/.NET, especially when dealing with driver lifecycle, sessions/transactions, result streaming, and type-safe record mapping.

Core Features & Use Cases

  • Driver lifecycle and safe disposal: Establishes a single thread-safe IDriver per application and uses await using for correct IAsyncDisposable behavior.
  • Managed transactions for correctness and retry safety: Guides when to use ExecuteReadAsync/ExecuteWriteAsync versus explicit transactions, and how to keep managed callbacks idempotent.
  • Result consumption and mapping: Explains Cursor handling (FetchAsync, ToListAsync, ConsumeAsync, SingleAsync) and robust record value access with .Get<T>()/.As<T>() including null and absent-key scenarios.
  • Practical .NET integration patterns: Covers DI registration as a singleton, cancellation token propagation, UNWIND batching parameterization, and Preview object mapping with AsObject<T>/AsObjectsAsync<T>().
  • Error handling and common traps: Provides an exception-handling approach (e.g., ClientException vs Neo4jException) and a checklist of frequent mistakes.

Quick Start

Use this skill to correctly implement Neo4j.Driver v6 in your C# service by registering IDriver as a singleton and running read/write operations with ExecuteReadAsync/ExecuteWriteAsync while consuming results inside the managed transaction callback.

Frequently Asked Questions about neo4j-driver-dotnet-skill

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I configure the Neo4j .NET driver lifecycle with dependency injection?

Register a single thread-safe IDriver instance as a singleton in your DI container. Use await using with IAsyncDisposable to ensure correct driver disposal and safe connection pool management across your application.

What's the best way to execute Neo4j managed transactions in C#?

Use ExecuteReadAsync and ExecuteWriteAsync for managed transactions with automatic retry safety. Keep transaction callbacks idempotent and consume all results within the callback scope to avoid cursor misuse errors.

How does result consumption work with the Neo4j C# driver?

Result consumption uses cursor handling methods like FetchAsync, ToListAsync, ConsumeAsync, and SingleAsync. Access record values robustly using .Get<T>() or .As<T>() to handle type mapping, including null and absent-key scenarios.

Why does my Neo4j C# managed transaction fail after the callback scope?

Cursors are invalid outside their managed transaction callback scope. Missing awaits during async execution also cause failures. Consume results completely within the callback and propagate cancellation tokens correctly.

Can I use parameterized batching with the Neo4j .NET driver?

Yes, use UNWIND batching with parameterization for efficient bulk operations. The driver also supports Preview object mapping with AsObject<T>() and AsObjectsAsync<T>() for direct type-safe object projection from query results.

How should I handle Neo4j exceptions in my C# data access layer?

Distinguish between ClientException and general Neo4jException types for appropriate error handling. Follow the provided exception-handling approach and common mistake checklist to avoid frequent pitfalls like missing awaits and cursor misuse.