-
Notifications
You must be signed in to change notification settings - Fork 4
Home
This library is created with dotnet 8, this means the host project must be implemented with dotnet 8 to be able to integrate this library.
To get started with the library, you can install it with the following command.
dotnet add package Neo4j.Berries.OGM
First make sure you have added the following to your appsettings.json
. The OGM library will use it to make a connection with neo4j.
{
"Neo4j": {
"Url": "",
"Username": "",
"Password": "",
"Database": "" //optional
}
}
Note: In case it is needed to use the default database, do not set the Database
property. When this property is set, the library will open the sessions against the mentioned database.
As in Ef Core we need to extend the DbContext
to define our DbSet<>
, We need here to extend the GraphContext
to define our NodeSet<>
. Each NodeSet<>
is considered a repository since the CRUD to each node is isolated to each NodeSet<>
. You can define your graph context like below.
public class MyGraphContext(Neo4jOptions options): GraphContext(options)
{
public NodeSet<Movie> Movies { get; private set; }
public NodeSet<Person> People { get; private set; }
}
Now that you have the GraphContext
set up, you can add it to the dotnet's dependency injection.
builder.Services.AddNeo4j<MyGraphContext>(builder.Configuration, typeof(Program).Assembly);
Note
The GraphContext exposes DatabaseContext
and you can access an open session to run custom cypher queries. (available from v1.1.0)
graphContext.Database.Session.Run(cypher);