Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store enum as integer in RavenDB

I would like to store Enums as integer-values inside a RavenDB-document instead of there full-name. Doing so, I would like to ensure, that changing the name of an enum-value, does not break persistence.

With FluentNHibernate, I can create a custom convention, but I didn't find anything matching with RavenDB.

like image 381
Daniel Lang Avatar asked Jul 21 '11 13:07

Daniel Lang


2 Answers

You can now just do:

store.Conventions.SaveEnumsAsIntegers = true;
like image 166
David Pfeffer Avatar answered Oct 24 '22 04:10

David Pfeffer


You can do that by creating a JsonConverter to do this, then add it to the documentStore.Conventions.Converters.

In fact, we store the name explicitly, so you can just remove the EnumJsonConverter from documentStore.Conventions.Converters

like image 8
Ayende Rahien Avatar answered Oct 24 '22 06:10

Ayende Rahien