开发者

Store enum as integer in RavenDB

开发者 https://www.devze.com 2023-03-21 19:31 出处:网络
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 persistenc

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 conventi开发者_C百科on, but I didn't find anything matching with RavenDB.


You can now just do:

store.Conventions.SaveEnumsAsIntegers = true;


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


As of today you can do this:

store.Conventions.CustomizeJsonSerializer = jsonSerializer =>
{   
    jsonSerializer.Converters.Remove(jsonSerializer.Converters.Where(c =>
    c.GetType() == typeof(JsonEnumConverter)).First());
}; 

store.Conventions.QueryEnumsAsIntegers = true;

Source: http://groups.google.com/group/ravendb/browse_thread/thread/18fef7b38252b27d

0

精彩评论

暂无评论...
验证码 换一张
取 消