This example demonstrates the fundamental Create, Read, Update, Delete (CRUD) operations using the GraphModel library with Neo4j.
- How to define domain models using
NodeandRelationshiprecords - Creating nodes and relationships in the graph
- Querying data using LINQ-to-Cypher
- Updating existing graph data
- Deleting nodes and relationships
- Using C# 13 record types with GraphModel
The example uses a simple organizational structure:
- Person: Represents employees with properties like Name, Email, Age, and Department
- Company: Represents companies with Name, Industry, and Founded date
- WorksFor: Relationship connecting Person to Company with Position, StartDate, and Salary
[Node("Person")]
public record Person : Node { ... }
[Relationship("WORKS_FOR")]
public record WorksFor : Relationship<Person, Company> { ... }await graph.CreateAsync(person);
await graph.CreateAsync(relationship);var people = await graph.NodesAsync<Person>()
.Where(p => p.Department == "Engineering")
.ToListAsync();var updatedPerson = person with { Age = 31 };
await graph.UpdateAsync(updatedPerson);await graph.DeleteAsync(person);- Neo4j instance running on
localhost:7687 - Username:
neo4j - Password:
password
cd examples/Example1.BasicCRUD
dotnet runThe example will:
- Create company and employee nodes
- Create work relationships
- Query and display the data
- Update some properties
- Demonstrate deletion
- Show verification of all operations
This example provides a foundation for understanding how to work with graph data using the GraphModel library.