In the mailing list, we got asked about an issue with code that looked like this:
I fixed the bug, but that was a strange thing to do, I thought. Happily, the person asking that question was actually taking part of a RavenDB course and I could sit with him and understand the whole question.
It appears that in their system, they have a lot of things like that:
And along with that, they also have a coordinating class:
The question was, could they keep using the same approach using RavenDB? They were quite anxious about this, since they had a need for the capabilities of this in their software.
This is why I hate Hello World questions. I could answer just the question that was asked, and that was it. But the problem is quite different.
You might have recognized it by now, what they have here is Entity Attribute Value system. A well known anti pattern for the relational database world and one of the few ways to actually get a dynamic schema in that world.
In RavenDB, you don’t need all of those things. You can just get things done. Here is the code that we wrote to replace the above monstrosity:
Not only will this class handle the dynamics quite well, it also serializes to idiomatic JSON, which means that querying that is about as easy as you can ask.
The EAV schema was created because RDBMS aren’t suitable for dynamic work, and like many other things from the RDMBS world, this problem just doesn’t exists for us in RavenDB.