Refactoring Model - circles-arrows/blueprint41 GitHub Wiki
This topic will guide you on how to refactor the Blueprint41 datastore model.
The database meta-model is defined in C# code and represents a stricter version of the neo4j schema. It defines the types of nodes, which properties they have and the relations the node type can have. The relations define the multiplicity of relationships. The database meta-model feels more like a class definition than a graph definition, which makes sense when you realize that the data eventually needs to be loaded into objects. Having a database meta-model in this way has the added advantage that the refactor actions can be applied to the data in the database as well as to the type-safe model.
To adjust the casing of the properties for the Movie and Person entity, go to "MovieGraph.Model" project, and select the file "Datastore.cs".
-
Create a new method
RefactorPropertiesand implement the code for refactoring theMovieandPersonentity properties. Please refer to the table below for the property changes:Entity CurrentProperty NewProperty Movie title Title tagline Tagline released Released Person name Name born Born
Important
Don't forget to set a Version attribute for the RefactorProperties method so that it will be included in the database update when running the application.
[Version(1, 0, 1)]
protected void RefactorProperties()
{
Entities["Movie"].Properties["title"].Refactor.Rename("Title");
Entities["Movie"].Properties["tagline"].Refactor.Rename("Tagline");
Entities["Movie"].Properties["released"].Refactor.Rename("Released");
Entities["Person"].Properties["name"].Refactor.Rename("Name");
Entities["Person"].Properties["born"].Refactor.Rename("Born");
}-
After implementing the code for refactoring the datastore model, the next step is to generate the type-safe models based on the updated data store model. Make sure to Build the
MovieGraph.Modelproject to generate type-safe generated models. See generate type-safe models. -
Run the "MovieGraph" application. Select Debug > Start Debugging or you can press F5.
Oops! There are errors while compiling the "MovieGraph" project. 😢

Since the database meta-model has changed by generating the type-safe models, the Movie and Person entity properties have now changed. Now, you need to update the codes that still uses the previous properties.
- To fix the errors, click each item in the error list and you will go directly to the line of codes that needs to be fixed.

To fix the query in the DisplayMoviesForActorName method, focus the cursor to the name and press Ctrl + Space to display the available members of the Person entity and select Name. You can also do the same to fix other properties of Person and Movie entity.

To fix the UpdateMovie and DeleteMovie methods, it uses the method LoadBytitle(string) but since the title property has changed to Title, the method Movie.LoadBytitle(string) will also changed its name to Movie.LoadByTitle(string).
Focus the cursor to the Movie.LoadBytitle(string) method and press Ctrl + Space, then select the Movie.LoadByTitle(string) method.


For the other errors, you can fix it similarly by applying the steps mentioned above.
After updating the codes, build the "MovieGraph" project to check if there are still errors.
- After the errors have been fixed and successfully build the project, perform this statement
MATCH (n:Movie) RETURN n LIMIT 25in the Neo4j browser to check the current properties of theMovieentity.

As you can see, the Movie property names have not yet changed.
- Comment other methods call except the
GetMoviesAndTheActorsmethod, then press F5 to run the "MovieGraph" application.

Voila! Your console application works perfectly again.
- In the Neo4j browser, perform this statement
MATCH (r:RefactorVersion) RETURN rto verify that your upgrade scriptVersion 1.0.1has successfully executed in the database.

- Perform this statement
MATCH (n:Movie) RETURN n LIMIT 25andMATCH (n:Person) RETURN n LIMIT 25in the Neo4j browser to check if theMovieandPersonentity successfully updated its property names.


Congratulations! 🎉 You've executed your upgrade script and refactored the Movie and Person entity successfully.