Git Product home page Git Product logo

neo4j.map.extension's Introduction

Neo4j.Map.Extension

Build status NuGet

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.

[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

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.

IDriver driver = GraphDatabase.Driver("bolt://127.0.0.1:7687", AuthTokens.None);
List<Employee> nodes = new List<Employee>();
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<Employee>());
    });
}

neo4j.map.extension's People

Contributors

italopessoa avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

neo4j.map.extension's Issues

create method to mount relation MATCH query

  • Add Neo4jRelation attribute
  • Add method to mount MATCH cypher query
  • Use a bool value to indicate if it should consider the properties
  • Add method to generate query based on one relation between two nodes

MATCH (u:User {uuid:"123"})-[r:HAS_FAILED]-(q:Question {uuid:"12"}) return u,r,q"

create method to mount MERGE relation query

criar metodo que gera um merge com os das propriedades valores da relacao
deve gerar uma nova relacoa caso nao exista

MERGE (u:User {uuid:"123"})-[r:HAS_FAILED]-(q:Question {uuid:"12"}) SET r.A = "bar"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.