0

I’m creating an ecommerce with products having their own fields (Id, Name): This is the object I have in c#

public class Product
{
  public int Id { get; set; }
  public string Name { get; set; }
}

This is my code to generate a product in C# to neo4j

Console.WriteLine("Generate node: ");
var newProduct = new Product{Id=666, Name="Banana"};
client.Cypher
      .Create("(product:Product {newProduct})")
      .WithParams(new { newProduct })
      .ExecuteWithoutResults();

Supposing a user or I need to add some other attributes, such as price to the product node, the first thing is to add a new Product attribute to the class

..
public int price { get; set; }
..

And then modify the cypher code to add the product with the net attribute/property.

Clearly this is a hardcoded approach, not good for a dynamic db/site.

Since I’ve been used to RDBMS this type of problem could only be solved with EAV and numerous pivots, I was hoping that Nosql (ie Neo4J) could have helped me in dealing with variable attributes fileds without EAV. Code that generates code could be a solution?

  • What comes in my mind is using Dynamic code/variable or codeDom, is this the way to go? are there other elegant solutions?
  • Please provide some explanations or topic to study.
  • NoSql should be schema-less but it’s schema-less application is not so easy am I correct?
Carlo Luther
  • 2,402
  • 7
  • 46
  • 75

1 Answers1

1

In a schema-free database the schema lives in the applications that use it.

You can make schema changes at least in the database with a tool like Liquigraph

If you change your objects you will have code that uses these new properties, so you have to adapt your code anyway, or?

You can write some code (or use the library if it supports it) to consume and hydrate arbitrary objects.

fbiville
  • 8,407
  • 7
  • 51
  • 79
Michael Hunger
  • 41,339
  • 3
  • 57
  • 80
  • Could expandoObject be a solution to create objects on the client side. I could store in a node in Neo4J all the fields as a dictionary-object serialized to Json. When a model is required from the client, I'd get back the Json data from the node, deserialize it and create object fields at runtime with expandoObject by adding to the class object all the fields that were stored as Json. I don't know the impanct on performance but I'm trying this path. Hope it works. – Carlo Luther Jan 12 '15 at 13:04
  • Yes, sounds workable. Not sure about the implications in c# though. – Michael Hunger Jan 12 '15 at 17:37