Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/italopessoa/neo4j.map.extension
A simple cypher query mapper in .NET.
https://github.com/italopessoa/neo4j.map.extension
cypher-query dotnet dotnet-core mapper neo4j neo4j-graph
Last synced: 2 days ago
JSON representation
A simple cypher query mapper in .NET.
- Host: GitHub
- URL: https://github.com/italopessoa/neo4j.map.extension
- Owner: italopessoa
- License: mit
- Created: 2018-03-07T02:03:05.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-30T12:54:42.000Z (about 6 years ago)
- Last Synced: 2025-01-04T21:19:32.945Z (19 days ago)
- Topics: cypher-query, dotnet, dotnet-core, mapper, neo4j, neo4j-graph
- Language: C#
- Homepage: https://www.nuget.org/packages/Neo4j.Map.Extension
- Size: 211 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Neo4j.Map.Extension
[![Build status](https://ci.appveyor.com/api/projects/status/65kgw70j31ra7hlt?svg=true)](https://ci.appveyor.com/project/italopessoa/neo4j-map-extension) [![NuGet](https://img.shields.io/badge/nuget-v1.0.1-blue.svg)](https://www.nuget.org/packages/Neo4j.Map.Extension/)
### What is Neo4j.Map.Extension?
Neo4j.Map.Extension is a simple tool that was born from an experiment while I was learning how to use Neo4j.Driver to execute queries in Neo4j. After some repetitive query parses, I tried to make it more abstract for me, using some attributes to configure a graph node as a custom C# class.
### Where can I get it?You can install Neo4j.Map.Extension using
#### Package Manager
`PM> Install-Package Neo4j.Map.Extension`#### Paket CLI
`> paket add Neo4j.Map.Extension`
#### .NET CLI
`> dotnet add package Neo4j.Map.Extension`#### How to use it?
There are two attributes that you can use to set up your custom class, ``Neo4jLabelAttribute`` to map your classes and ``Neo4jPropertyAttribute`` to map your properties. If you have any class which you want its properties values to be bind by ``Neo4j.Map.Extension``, it must inherit from ``Neo4jNode`` class.```C#
[Neo4jLabel("Employee")]
class Employee : Neo4jNode
{
[Neo4jProperty(Name = "name")]
public string Name { get; set; }[Neo4jProperty(Name = "occupation")]
public Ocuppation Ocuppation { get; set; }public override string ToString()
{
return $"Person {{Employee: '{UUID}', Name: '{Name}', Occupation: '{Ocuppation}'}}";
}
}
```
``UUID`` is a default property inherited from the ``Neo4jNode`` class. UUID is a value generated to guarantee that all your nodes have one unique identity value. You can read more about it on [neo4j-uuid](https://github.com/graphaware/neo4j-uuid)#### Map() - Binding node values to properties
Once you get the return from Neo4j server, you can use the ``Map`` extension method to check and bind all the values of you graph node into your custom class.
```C#
IDriver driver = GraphDatabase.Driver("bolt://127.0.0.1:7687", AuthTokens.None);
List nodes = new List();
using (ISession session = driver.Session(AccessMode.Read))
{
IStatementResultCursor result = await session.RunAsync("MATCH (n:Employee) return n");
await result.ForEachAsync(r =>
{
nodes.Add(r[r.Keys[0]].Map());
});
}
```