Hi Tom
I am still very new to Neo4j myself, so take my advice with a grain of salt. I was in a similar situation and found this blog helpful in the beginning:
From the above all my Model classes contains a AsDictionary method. Then you can create a method to generate a CREATE query which takes the Dictionary as input. This means you don't have to write individual CREATE queries for all your Models.
private static string CreateNodeQuery(Dictionary<string, object> properties, string type)
{
var query = new StringBuilder();
query.AppendLine($"CREATE (node: {type} {{");
foreach (KeyValuePair<string, object> property in properties)
{
if (property.Key != properties.Last().Key)
{
query.AppendLine($"{property.Key}: $node.{property.Key}, ");
}
else
{
query.AppendLine($"{property.Key}: $node.{property.Key} }} )");
}
}
query.AppendLine($"RETURN node");
return query.ToString();
}
Whether or not the above is a good solution, remains to be seem, but it seems to work in my case.
It gets more interesting when you have nested classes, as this, in my case, must be turned into a new node connected by a relationship. I solved this by using simple ViewModels to create nodes and relationships and then use the full model when retrieving nodes. For the last part I had a question answered here:
Hope it helps
Best regards
Andreas