Skip to content

gy2006/neo4j-dotnet-ogm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

neo4j-dotnet-ogm

Neo4j Object Graph Mapping Library for .NET

https://www.nuget.org/packages/Neo4jOgm/

Installation

Install-Package Neo4jOgm -Version 0.21.8

Quick start

Declare domain entities

[NeoNodeEntity("person", "p")]
public class Person
{
    [NeoNodeId]
    public long? Id { get; set; }
    
    public string Name { get; set; }
    
    [NeoRelationship("ARE_FRIENDS")]
    public List<Person> Friends { get; set; }
    
    [NeoCreatedAt]
    public DateTime? CreatedAt { get; set; }
    
    [NeoUpdatedAt]
    public DateTime? UpdatedAt { get; set; }
    
    [NeoIgnored]
    public string Extra { get; set; }
}

Setup

// make neo4j connection
var authToken = AuthTokens.Basic("neo4j", "12345");
var driver = GraphDatabase.Driver("bolt://localhost:7687", authToken);

// create context by Assembly and load entities
var context = new NeoContext(Assembly.GetExecutingAssembly());

// new repoistory
var repository = new NeoRepository(driver, "neo4j", context);


// Create an entity with relationship
var a = new Person {Name = "A"};
var b = new Person {Name = "B"};
a.Friends = new List<Person> {b};
var created = repository.Create(a);

// Update entity
created.Name = "New name"
repository.Update(created);

// Load entity and relationship by id
var loaded = repository.FindById<Person>(created.Id.Value, new RelationshipOption(){Load = true, Depth = 5});

// Find all entities and relationship with criteria
var crteria = new Criteria("Name", Operator.Equal, "A")
        .Or(new Criteria("Name", Operator.Equal, "B"));
        
var page = repository.FindAll<Person>(new PageRequest(1, 5), crteria, new RelationshipOption {Load = true});

// Delete entity and relationship by id
repository.DeleteById<Person>(created.Id.Value, true);

// Delete all
repository.DeleteAll<Person>();

Releases

No releases published

Packages

No packages published

Languages