berrybeat / Neo4j.Berries.OGM

This repository adds an OGM functionality for csharp
https://berrybeat.com/
MIT License
16 stars 1 forks source link

Neo4j relation properties object map #1

Open farhadnowzari opened 3 months ago

farhadnowzari commented 3 months ago

Is your feature request related to a problem? Please describe.

At the moment, the OGM library creates a relation between two nodes with just knowing about the relation's label. In Neo4j it is possible to define properties on relations and query with those properties

Describe the solution you'd like We need to define perhaps in the NodeConfig, how does the relation look like. Which interface it needs to implement as the relation, or which relation implementation it should take. This option better be optional, since not all relations will need to have properties.

The challenge to solve here is, when we define a properties class/interface on a relation, how do we integrate it in creation or queries? How will the design and class diagram looks like. We should have in mind to keep the node classes as lean as possible and don't include any of the library logic inside them, this way the developers can change their tech easier when they need to and the node classes are reusable easier.

farhadnowzari commented 2 months ago

The relation properties, could be introduced like the following:

public class Movie {
    public string Name { get; set; }

    public Relation<DirectsIn, Person> Director { get; set; }
    public List<Relation<ActsIn, Person>> Actors { get; set; }
}

graphContext.Movies.Add(movie);

graphContext
    .Movies
    .Match()
    .WithRelation(x => x.Director, /* relation search */ x => x.Where(), /* node search */ x => x.Where())

graphContext
    .Movies
    .Match()
    .WithRelation(x => x.Actors, /* relation search */ x => x.Where(), /* node search */ x => x.Where())
    .UpdateRelation()

graphContext
    .Movies
    .Match()
    .Connect(x => x.Director, x => x.Where(y => y.Name, "James Cameron"), new DirectsIn {})

The Relation model will not be mandatory for having a relation and the old property less relations can still exist with the old syntax. Also the relations will still be configured with FluentConfiguration.

farhadnowzari commented 2 months ago

3

related