Is it possible to update an F# entity in RavenDB without abandoning
immutability?
I have become a great fan of the powerful type system in F# and how it
allows you to create some very tight restraints on your domain models (for
those interested, see this). I have also become a great fan of RavenDB and
how it makes database work very simple in most of the cases I run into.
However, there seems to be issues getting the two to play nicely together
- at least if you insist on immutable types.
As long as you don't ever have to update your entities, all you need to do
is make the id property mutable. While I'm certainly not happy that this
is necessary, I can live with it. However, it seems that change tracking
is handled in such a way that you must mutate the original object
retrieved from the database and it is not possible to attach a new object
to the database to represent an updated version of an existing entity. It
does seem to be possible to do what I want using the patching API, but the
documentation clearly warns against this type of general usage.
Am I missing a part of the RavenDB API that will let me do this without
too much fuss or must I abandon the idea of immutable domain models (or
perhaps make a feature request for it)?
No comments:
Post a Comment