2

As a complete novice programmer I am trying to populate my neo4j DB with data from heterogeneous sources. For this I am trying to use the Neo4jClient C# API. The heterogeneity of my data comes from a custom, continuously evolving DSL/DSML/metamodel that defines the possible types of elements, i.e. models, thus creating classes for each type would not be ideal.

As I understand, my options are the following:

  1. Have a predefined class for each type of element: This way I can easily serialize my objects that is if all properties are primitive types or arrays/lists.
  2. Have a base class (with a Dictionary to hold properties) that I use as an interface between the models that I'm trying to serialize and neo4j. I've seen an example for this at Can Neo4j store a dictionary in a node?, but I don't understand how to use the converter (defined in the answer) to add a node. Also, I don't see how an int-based dictionary would allow me to store Key-Value pairs where the keys (that are strings) would translate to Property names in neo4j.
  3. Generate a custom query dynamically, as seen at https://github.com/Readify/Neo4jClient/wiki/cypher#manual-queries-highly-discouraged. This is not recommended and possibly is not performant.

Ultimately, what I would like to achieve is to avoid the need to define a separate class for every type of element that I have, but still be able to add properties that are defined by types in my metamodel.

I would also be interested to somehow influencing the serializer to ignore non-compatible properties (similarly to XmlIgnore), so that I would not need to create a separate class for each class that has more than just primitive types.

Thanks, J

Community
  • 1
  • 1
Janos
  • 101
  • 1
  • 6

1 Answers1

0

There are 2 problems you're trying to solve - the first is how to program the C# part of this, the second is how to store the solution to the first problem.

At some point you'll need to access this data in your C# code - unless you're going fully dynamic you'll need to have some sort of class structure.

Taking your 3 options:

  1. Please have a look at this question: neo4jclient heterogenous data return which I think covers this scenario.

  2. In that answer, the converter does the work for you, you would create, delete etc as before, the converter just handles the IDictionary instance in that case. The IDictionary<int, string> in the answer is an example, you can use whatever you want, you could use IDictionary<string, string> if you wanted, in fact - in that example, all you'd need to do would be changing the IntString property to be an IDictionary<string,string> and it should just work.

  3. Even if you went down the route of using custom queries (which you really shouldn't need to) you will still need to bring back objects as classes. Nothing changes, it just makes your life a lot harder.

In terms of XmlIgnore - have you tried JsonIgnore? Alternatively - look at the custom converter and get the non-compatible properties into your DB.

Community
  • 1
  • 1
Charlotte Skardon
  • 6,220
  • 2
  • 31
  • 42
  • Fully dynamic and without any class structure is the norm for us. We have millions of structures that shift all the time and if each piece of code had to have classes we'd have a maintenance nightmare. Fully dynamic is just as fast, in our use cases anyway! – Max Murphy Apr 17 '15 at 15:53