Neo4jClient.Extension.Attributes 4.0.3

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Neo4jClient.Extension.Attributes --version 4.0.3
                    
NuGet\Install-Package Neo4jClient.Extension.Attributes -Version 4.0.3
                    
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="Neo4jClient.Extension.Attributes" Version="4.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Neo4jClient.Extension.Attributes" Version="4.0.3" />
                    
Directory.Packages.props
<PackageReference Include="Neo4jClient.Extension.Attributes" />
                    
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 Neo4jClient.Extension.Attributes --version 4.0.3
                    
#r "nuget: Neo4jClient.Extension.Attributes, 4.0.3"
                    
#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 Neo4jClient.Extension.Attributes@4.0.3
                    
#: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=Neo4jClient.Extension.Attributes&version=4.0.3
                    
Install as a Cake Addin
#tool nuget:?package=Neo4jClient.Extension.Attributes&version=4.0.3
                    
Install as a Cake Tool

Neo4jClient.Extension

NuGet Version Build Status License

A fluent API extension for Neo4jClient that simplifies building Cypher queries using strongly-typed C# objects.

Features

  • Type-Safe Query Building - Create, match, and merge nodes and relationships using objects instead of writing Cypher strings
  • Fluent Configuration - Configure entity metadata without cluttering domain models with attributes
  • Relationship Modeling - Strongly-typed relationships with properties
  • IntelliSense Support - Full IDE autocomplete for improved productivity
  • Reduced Errors - Compile-time checking prevents property name typos and refactoring issues

Key Extension Methods

  • CreateEntity<T> - Create nodes from objects
  • MergeEntity<T> - Merge nodes with ON CREATE/ON MATCH support
  • MatchEntity<T> - Match nodes by properties
  • CreateRelationship<T> - Create typed relationships
  • MergeRelationship<T> - Merge relationships
  • MatchRelationship<T> - Match relationships

Quick Start

Installation

# Install Neo4jClient
dotnet add package Neo4jClient

# Install Neo4jClient.Extension
dotnet add package Neo4jClient.Extension

Setup

using Neo4jClient;
using Neo4jClient.Extension.Cypher;

// Connect to Neo4j
var client = new BoltGraphClient(new Uri("bolt://localhost:7687"), "neo4j", "password");
await client.ConnectAsync();

// Configure your entities (do this once at startup)
FluentConfig.Config()
    .With<Person>()
    .Match(x => x.Id)
    .Merge(x => x.Id)
    .MergeOnCreate(p => p.DateCreated)
    .Set();

Fluent Configuration

Configure entity metadata once at application startup without decorating your domain models:

FluentConfig.Config()
    .With<Person>("SecretAgent")
    .Match(x => x.Id)
    .Merge(x => x.Id)
    .MergeOnCreate(p => p.DateCreated)
    .MergeOnMatchOrCreate(p => p.Name)
    .MergeOnMatchOrCreate(p => p.Title)
    .Set();

Configure relationships with properties:

FluentConfig.Config()
    .With<HomeAddressRelationship>()
    .MergeOnMatchOrCreate(hr => hr.DateEffective)
    .Set();

Usage Examples

Create a Node

var person = new Person { Id = 1, Name = "John Doe" };
await client.Cypher
    .CreateEntity(person, "p")
    .ExecuteWithoutResultsAsync();

Create Nodes with Relationships

var person = new Person { Id = 1, Name = "John Doe" };
var address = new Address { Street = "123 Main St", City = "Austin" };

await client.Cypher
    .CreateEntity(person, "p")
    .CreateEntity(address, "a")
    .CreateRelationship(new HomeAddressRelationship("p", "a"))
    .ExecuteWithoutResultsAsync();

Merge Nodes

var person = new Person { Id = 1, Name = "John Doe", DateCreated = DateTime.UtcNow };

await client.Cypher
    .MergeEntity(person)  // Uses configured Merge properties
    .MergeEntity(person.HomeAddress)
    .MergeRelationship(new HomeAddressRelationship("person", "homeAddress"))
    .ExecuteWithoutResultsAsync();

Alternative: Attribute Configuration

For those who prefer attributes, you can decorate your models directly:

[CypherLabel(Name = "Person")]
public class Person
{
    [CypherMerge]
    public Guid Id { get; set; }

    [CypherMergeOnCreate]
    public string Name { get; set; }

    [CypherMergeOnMatchOrCreate]
    public bool IsActive { get; set; }
}

Available Attributes:

  • CypherLabel - Custom node label (defaults to class name)
  • CypherMatch - Used in MATCH clauses
  • CypherMerge - Used in MERGE clauses
  • CypherMergeOnCreate - Set only when creating (ON CREATE SET)
  • CypherMergeOnMatch - Set only when matching (ON MATCH SET)

Note: Fluent configuration is recommended to keep domain models infrastructure-free.

Relationship Modeling

Define strongly-typed relationships by inheriting from BaseRelationship:

[CypherLabel(Name = "HOME_ADDRESS")]
public class HomeAddressRelationship : BaseRelationship
{
    public HomeAddressRelationship(string fromKey, string toKey)
        : base(fromKey, toKey) { }

    public DateTime DateEffective { get; set; }
}

Development

Building

dotnet build Neo4jClient.Extension.sln

Running Tests

Unit Tests:

dotnet test test/Neo4jClient.Extension.UnitTest/

Integration Tests (requires Neo4j):

# Automated setup (recommended)
./run-tests-with-neo4j.sh      # Linux/macOS
run-tests-with-neo4j.bat        # Windows

# Manual setup
docker compose up -d neo4j
dotnet test --filter Integration
docker compose down

Packaging

powershell -f build.ps1 -packageVersion 1.0.0

Output: ./_output/ directory

Documentation

Requirements

  • .NET 9.0 or later
  • Neo4jClient 4.0.0+
  • Neo4j 5.x (for integration tests)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the terms specified in the LICENSE file.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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 (2)

Showing the top 2 NuGet packages that depend on Neo4jClient.Extension.Attributes:

Package Downloads
Neo4jClient.Extension

Package Description

Neo4j.Tools.Write

This library aims at pushing a complex graph of entities into a Neo4j database by matching objects with nodes, and navigation properties with relations.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
5.0.0-beta.1-24 106 10/20/2025
4.0.3 166 10/20/2025
4.0.0-beta.1-17 106 10/20/2025
4.0.0-beta.1-12 105 10/20/2025
1.0.2 9,585 2/3/2017
1.0.1 7,905 2/21/2016
1.0.0 1,587 9/29/2015
0.1.3.1 1,472 8/23/2015
0.1.3 1,445 8/13/2015
0.1.0 4,938 2/19/2015