Created
December 1, 2017 19:40
-
-
Save rofr/6c75fe686b74c6758ab7f13af4b8b987 to your computer and use it in GitHub Desktop.
Memstate movie model - strongly typed graphs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//define actor node type | |
class Actor { | |
String Name; | |
Set<Role> Movies; | |
} | |
//define movie node type | |
class Movie { | |
String Name; | |
Set<Role> Roles; | |
} | |
/* A relationship modeled as a class */ | |
class Role { | |
String Name; | |
Actor Actor; | |
Movie Movie; | |
} | |
class Model { | |
Set<Actor> Actors; | |
Set<Movie> Movies; | |
} | |
/* populate the graph */ | |
// create nodes | |
var matrix = new Movie("Matrix"); | |
var keanu = new Actor("Keanu Reeves"); | |
//create an edge with properties | |
//notice that we can navigate from the edge to each node | |
var role = new Role { | |
Name = "Neo", | |
Actor = keanu, | |
Movie = matrix | |
}; | |
//add the edge to each node | |
keanu.Roles.Add(role); | |
matrix.Roles.Add(role); | |
//set up the root graph | |
var model = new Model(); | |
model.Actors.Add(keanu); | |
model.Movies.Add(matrix); | |
var movies = model.Movies.Where(m => m.Roles.Any(r => r.Actor == keanu)).Distinct(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment