![]() |
VOOZH | about |
dotnet add package SchematicNeo4j --version 5.0.2
NuGet\Install-Package SchematicNeo4j -Version 5.0.2
<PackageReference Include="SchematicNeo4j" Version="5.0.2" />
<PackageVersion Include="SchematicNeo4j" Version="5.0.2" />Directory.Packages.props
<PackageReference Include="SchematicNeo4j" />Project file
paket add SchematicNeo4j --version 5.0.2
#r "nuget: SchematicNeo4j, 5.0.2"
#:package SchematicNeo4j@5.0.2
#addin nuget:?package=SchematicNeo4j&version=5.0.2Install as a Cake Addin
#tool nuget:?package=SchematicNeo4j&version=5.0.2Install as a Cake Tool
A code-first approach to manage a consistent Neo4j graph schema for a domain layer that is defined in a .NET library.
typeof(Class1).Label() makes autocomplete method discovery difficult. I'd like to simplify that.Relationship Range Index was added in v5.0.0 and works the same as Indexes on Nodes, except that it ignores the Label and IsAbstract properties.
The Indexes.Create() logic uses the class level attribute to differentiate between Relationship | Node.
[Relationship]
public class PlaysFor {
[Index()]
[Index(Name="PlaysFor_YearPosition")]
public int Year { get; set; }
[Index(Name="PlaysFor_YearPosition")]
public string Position { get; set; }
}
[Node(Label="Person:Player")]
public class Player : Person {
[Index(Label="Player")]
public string Postion {get; set;}
}
Example creates 3 Indexes (all range indexes by default): 1. Relationship Range Index with default name idx_PlaysFor_Year 2. Relationship Range Index with name PlaysFor_YearPosition 3. Node Range Index with name idx_Player_Position
Annotate the class with a RelationshipAttribute (optionally provide a Type, defaults to the class name in proper format).
[Relationship]
public class PlaysFor {}
[Relationship(Type="PLAYS_FOR")]
public class Class1 {}
Results for both are ()-[:PLAYS_FOR]-()
Annotate the class with a NodeAttribute (or it can also default to the class name)
[Node(Label = "Person")]
public class Class1 {}
public class Person {}
[Node]
public class Person {}
Annotate the properties that make up the Node Key
public class Car {
[NodeKey]
public string Make { get; set; }
[NodeKey]
public string Model { get; set;}
}
Name your NodeKey; useful in cases of existing constraints or your project uses a specific naming convention. The default is nk[firstLabel].
[Node(Label="Car:Vehicle", NodeKey="nkCar")]
public class Car {
[NodeKey]
public string Make { get; set; }
[NodeKey]
public string Model { get; set;}
}
If you want to differentiate between 2 subclasses of an object but they are going to share the same node key, defined by the super class. We can do something like this.
public class Person {
[NodeKey]
public string FirstName { get; set; }
[NodeKey]
public string LastName { get; set;}
}
[Node(Label="Person:Coach")]
public class Coach : Person {
public int YearStarted {get; set;}
}
[Node(Label="Person:Player")]
public class Player : Person {
public string Postion {get; set;}
}
Both players and coaches have a name; players can be coaches, and vice versa. Either way, this keeps our data clean preventing a person from having 2 records in the system.
There are a few provided extensions that we can take advantage of when using the CustomAttributes. Assume the following Vehicle definition:
public class Vehicle {
[NodeKey]
public string Make { get; set; }
[NodeKey]
public string Model { get; set;}
[NodeKey]
public string ModelYear { get; set; }
}
// for a type
var theLabel = typeof(Vehicle).Label();
// for a type
List<string> vehicleNodeKey = typeof(Vehicle).NodeKey();
// for a type
string vehicleNodeKeyName = typeof(Vehicle).NodeKeyName();
Once we have our domain models identified we can use the Schema methods to put it into the graph. You can pass in either an entire assembly, a list, or a single Type.
This will create the indexes for both entity types, node and relationship.
// Pass an Assembly and driver
SchematicNeo4j.Schema.Initialize(assembly:Assembly.GetAssembly(typeof(DomainSample.Person)), driver);
// Pass a list of domain types
// Get this assembly
Assembly a = Assembly.GetExecutingAssembly();
// Limit to a specific namespace.
var listOfTypes = a.ExportedTypes.Where(t => t.Namespace == "MyExecutingThing.MyDomain").ToList();
SchematicNeo4j.Schema.Initialize(listOfTypes, driver);
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 is compatible. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 5.0.2 | 340 | 4/25/2024 |
| 5.0.1 | 239 | 4/16/2024 |
| 5.0.0 | 206 | 4/11/2024 |
| 1.3.0 | 826 | 10/2/2020 |
| 1.0.0 | 756 | 11/19/2019 |
| 0.1.2-beta | 646 | 6/18/2019 |
| 0.1.1-beta | 627 | 6/17/2019 |
| 0.1.0-beta | 664 | 6/7/2019 |
Version 5.0.2: Fixed classes with multiple labels and inherited nodekeys from a parent class to work as it previously did.
Version 5.0.0: version in line with Neo4j.
- Updated to work with neo4j graph version 4.4 -> 5.x and neo4j-dotnet-driver 5.17
- Added target for net8.0LTS and netframework 4.8.1
- Added Indexes on Relationship Entities
- various updates to work with neo4j v4+ changes to index and constraints, instead of faking those features.
Version 1.3.0: Updated to use neo4j-dotnet-driver 4.x with graph version 3.5.x (3.5.17 and 3.5.21 were tested).
Version 1.0.0: Added Index management with Index object that maps to the IndexAttribute.
- Index matching is done by Label and Properties for neo4j version 3.x
- Create/Drop of indexes added to Schema.Initialize and Schema.Clear
- IndexAttribute with Name, Label, Properties, and IsAbstract.
- IsAbstract allows for Indexes to utilize inherited properties and prevents partial indexes from being created.
Version 0.1.2-beta: Fix bug with a type having a partial name match to another type (ex: Car => RedCar)
Version 0.1.1-beta: Adds inherited, or shared, node keys.
Version 0.1.0-beta: Initial Release with methods that can accept an assembly, a collection of types, or a single type.
Methods:
Schema.Initialize
Schema.Clear
NodeKey.Create/Drop/Exists/MatchesExisting
Index.Create/Drop/Exists
Type.Indexes/CreateIndexes/DropIndexes